Tags: mikeal/ipjs
Tags
fix: require regular version in stubs (#20) When we stub files for environments that do not handle export maps very well, we `require` a transpiled CJS implementation and re-export it in a stub file that should be immediately overridden by the `browser` or `exports` fields in `package.json`. At the moment we use the value from the `browser` overrides to work out which file we should `require` the stub. The change here is to `require` the transpiled regular CJS version in the stub instead of the browser override. Turns out when Jest has `testEnvironment: 'node'` set it resolves `require`s to the stubs, ignoring `exports` which loads browser-specific code into node with predictably incendiary results.
feat: support single exports (#18) The following are all valid values for the `"exports"` map (https://nodejs.org/api/packages.html#packages_exports_sugar): ``` "exports": { ".": { "import": "./index.js" } } ``` ``` "exports": { "import": "./index.js" } ``` ``` "exports": "./index.js" ``` Currently ipjs only supports the first version, this PR adds support for the other two as well.
docs: update readme to require named exports Unless I've missed some clever hack, default exports are basically incompatible with the (common?) combination of cjs/jsdoc/node/browsers and tsc, I think because `typesVersions` only ever follows the `import` path and not the `require` path.
fix: work with jest (#14) Jest [doesn't support package exports](jestjs/jest#9771), nor does it support `browser` overrides out of the box (though it [can be configured](https://jestjs.io/docs/configuration#resolver-string)). This means it parses the stubbed files introduced in #13 as javascript, so let's just require and export the file that the stub is stubbing. This has the added bonus of also supporting old nodes that don't understand package exports. Fixes achingbrain/uint8arrays#21
fix: work with browserify (#13) Browserify [does not support](browserify/resolve#224) `"exports"` in a `package.json`, and nor can you use `"browser"` in `package.json` [as a hint to Browserify to look in a certain place for a file](browserify/resolve#250 (comment)). This means the output of `ipjs` is not compatible with Browserify since it expects the runtime/bundler to use the `"exports"` field to look up files paths. If Browserify finds a file path, it will then use the `"browser"` values to apply any overrides, which `ipjs` uses to direct it to the `/cjs` folder. The problem is if it can't find the file in the first place it won't use the `"browser"` map to get the overrides. Handily we're generating the `"browser"` field values from the `"exports"` values so we know we have the complete set of files that the user wants to expose to the outside world, and the paths we want people to use to access them. The change in this PR is to use the `"browser"` field values to [mimc the `"exports"` structure in a CJS-compatible directory structure](browserify/resolve#250 (comment)) as per @ljharb's suggestion. For any file that we are overriding with `"browser"` values, we create an empty file (where a resolvable file does not already exist) a the path Browserify expects it to be at, then it'll dutifully use the `"browser"` field to pull the actual file in.
fix: add esm and cjs paths to browser map for overriden files (#12) * fix: add esm and cjs paths to browser map for overriden files See evanw/esbuild#1443 for discussion. In brief if you have a project that is built by ipjs and you have file A that imports file B, esbuild (maybe others?) resolves file B using it's full path within the module (e.g. including `esm` or `cjs`), which it then uses as a key to look up overrides in the `browser` map in your `package.json`. If there is an override it'll fail to be found because ipjs doesn't add paths prefixed with `esm` or `cjs` to the browser map where overrides have been delcared in the `exports` map, so the change here is to add files with their full path prefix to the `browser` map. * fix: browser overrides in webpack
PreviousNext