Skip to content

Fix exports field in package.json #351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 18, 2023
Merged

Conversation

fisker
Copy link
Contributor

@fisker fisker commented Feb 14, 2022

Fixes #350

A solution that postss used seems unnecessary, as I tested, use "./*": "./*" works on Node.js 12 too.

@fisker fisker changed the title Fix exports field in package.json Fix exports field in package.json Feb 14, 2022
@fisker
Copy link
Contributor Author

fisker commented Feb 16, 2022

@kpdecker Can you take a look?

@ExplodingCabbage
Copy link
Collaborator

A solution that postss used seems unnecessary, as I tested, use "./": "./" works on Node.js 12 too.

I think you probably tested on 12.20 or later, but that it's necessary for earlier versions? The history at https://nodejs.org/docs/latest-v12.x/api/packages.html#packages_modules_packages says that support for patterns (i.e. use of *) in exports was only added in version 12.20. Some testing confirms this; if I install jsdiff from local source with npm install --save ../jsdiff and try require("diff/lib/patch/create.js"), in Node 12.19 or earlier I need ./ in the exports section or else I get:

$ node
Welcome to Node.js v12.19.1.
Type ".help" for more information.
> require("diff/lib/patch/create.js")
Uncaught:
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/patch/create.js' is not defined by "exports" in /home/mark/marktest2/node_modules/diff/package.json
    at throwExportsNotFound (internal/modules/esm/resolve.js:285:9)
    at packageExportsResolve (internal/modules/esm/resolve.js:491:3)
    at resolveExports (internal/modules/cjs/loader.js:444:36)
    at Function.Module._findPath (internal/modules/cjs/loader.js:484:31)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:818:27)
    at Function.Module._load (internal/modules/cjs/loader.js:687:27)
    at Module.require (internal/modules/cjs/loader.js:903:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at repl:1:1
    at Script.runInThisContext (vm.js:120:18) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

So let's go for the postcss solution of including both ./ and ./*, just for maximum compatibility.

@ExplodingCabbage ExplodingCabbage merged commit 976d60d into kpdecker:master Dec 18, 2023
@fisker fisker deleted the exports branch December 18, 2023 23:41
ExplodingCabbage added a commit that referenced this pull request Apr 28, 2025
* First steps towards TypeScript conversion

* Convert xml.js->xml.ts

* Add compilation to build step

* Rewrite base.js in TypeScript (maybe shit, need to review own work once I'm done)

* Rewrite json.js -> json.ts and get tests passing (I'm honestly shocked they passed)

* array.js -> array.ts

* character.js -> character.ts

* css.js->css.ts

* sentence.js->sentence.ts

* word.js -> word.ts

* line.js -> line.ts

* index.js->index.ts

* Convert a couple more fiiles

* Convert params.ts

* string.js -> string.ts

* Partly convert patch-related files to TypeScript; more to do

* Type more stuff

* Begin converting line-endings.js. Interesting TypeScript bug along the way.

* Bump TypeScript

* Add link to bug report

* Finish converted line-endings.js to TypeScript

* Add missing overloads to support case where argument type isn't known statically

* reverse.js -> reverse.ts

* add todo

* Rewrite base.ts types (breaks everything for now)

* Per-diff-function options types. Still not compiling but close.

* Fix build

* Run 'yarn add @eslint/js typescript-eslint --save-dev' as suggested at https://typescript-eslint.io/getting-started

* Turn on recommended eslint rules as recommended by Getting Started guide at https://typescript-eslint.io/packages/typescript-eslint/#config

* Get linting of TypeScript working (now with the officially recommended rules)

* yarn lint --fix

* Tweak some indentation that eslint broke

* Fix a couple of linting errors

* Allow explicit 'any'

I'm using it and it's convenient. In some places like diffArrays where we allow arrays of arbitrary type, I don't even know how to NOT use it.

* Eliminate needless explicit respecification of rules that eslint.configs.recommended already enables

* Fix another eslint config bug

* Start using arrow functions and thereby resolve a https://typescript-eslint.io/rules/no-this-alias/ error

I wasn't using them before because I wasn't sure if our build process would turn them into normal functions for compatability with old JS environments; it turns out it does, so we're fine.

* Fix some linting errors about pointless escape sequences

* Fix more linting errors about pointless escape sequences

* Eliminate a util made redundant by Object.keys, and fix a linting error in the process

* Fix a no-prototype-builtins linting error

* Disable no-use-before-define for TypeScript code, where it's broken

* Liberalise more rules

* Fix lint errors in parse.ts

* Fix lint errors in apply.ts

* Fix remaining linting errors

* Add missing newline at EOF

* Remove a couple of unused ts-expect-error directives. (My editor was showing errors but tsc doesn't.)

* create.js->create.ts

* Fix some linting errors

* Lint on build, like before

* Generate type declarations on build

* Migrate to using tsconfig.json instead of CLI args

* Start adding tsd tests... but actually maybe should use dtslint?

* Correctly mark a load of arguments as optional

* convert tests to tsd style

* Fix type test

* Fix some more type test things

* Undo some testing silliness

* aaaaaaaaaaargh

* Get most of the way to fixing type definitions based on #303 (comment). Doesn't compile yet.

* Fix index.ts

* Fix remaining compilation errors

* Restore 'Change' type from DefinitelyTyped

* tsd test syntax fix

* Fix: oldHeader & newHeader are allowed to be explicitly given as undefined

* Fix 'Abortable' types in patch/create

* Fix another typing error

* Fix error-handling-related types in patch/apply

* Analyse errors I'm seeing in tests copied from DT & add TODOs

* Begin adding some docs

* Fix a load of test cases where the DT behaviour was just wrong

* Make diffArrays generic instead of using any

* Make DiffArraysOptions types generic

* Rename ParsedDiff -> StructuredPatch

* Export ApplyPatchOptions, ApplyPatchesOptions

* Make all methods public for backwards compat

* Fix remaining type error

* Fix ignoring of test-d

* Copy latest change from DT (DefinitelyTyped/DefinitelyTyped@2cfdb9f)

* Flesh out docs

* Resolve ignoreWhitespace dilemma

* nah

* Remove obsolete TODOs

* Fix bad .gitignore rule

* Add another type test file

* v0.0.1

* v0.0.2

* .npmignore more stuff

* Move test-d/ out of types/ so yarn clean won't delete it

* Add attw

* durrrr

* failed fix attempt

* Get attw passing (hallelujah!)

* Enable "strict": true

* Fix a strict mode error

* Fix a strict mode error

* Fix more strict mode errors

* Silence a silly strict mode error

* Further placate strict mode

* Further placate strict mode

* Fix a legit type error that strict mode found

* Further placate strict mode

* Get TypeScript happy with create.ts

* Further placate strict mode

* Further placate strict mode

* Placate compiler about apply.ts

* Fix a load more strict mode errors

* Placate strict mode further

* Fix some more compilation errors

* Fix one more compilation error

* Fix remaining base.ts errors

* Fix line.ts

* Type a variable to remove a slew of compilation errors

* Add more types to resolve more errors

* Add even more types to resolve even more errors

* Fix remaining type errors. Huzzah!!!

* Address verbatimModuleSyntax guidance

* Remove obsolete comment

* Get @typescript-eslint/consistent-type-exports enabled

* Un-disable no-duplicate-type-constituents and let it autofix. I guess I was confused.

* Reenable another rule

* Remove no-longer-needed gitignore rule from earlier in this PR

* Remove an obsolete disabling of a rule from early in my eslint tinkering. No longer makes sense.

* Fix deps being wrongly declared as non-dev deps

* Bump new deps to latest

* Re-add support for imports from /lib/, maybe?

* Restore support for subpath imports in Node 12.19 and earlier (see #351 (comment)).

* Restore es5 support

* Improve docs; add more exports to obviate need to import stuff from lib/

* Fix rollup

* Improve docs; restore package.json top-level fields that maybe are useful for compatibility with something, somewhere

* Stop using babel with rollup.

Doesn't seem to really affect anything. Output in dist/diff.js is almost identical; just formatting changes and a handful of other things that look inconsequential.

* Remove unused dependency on Babel CLI

* Remove another unused dep

* Get karma working

* Remove apparently unneeded eslint ignore directives

* Fix misplaced bullet in release notes

* bah

* Begin the tedious work of copying and pasting the README documentation into the function comments, so it can show up in people's editors

* More copying and pasting. I should probably test this before moving on

* More copying and pasting of docs

* Finish pasting docs

* Revert temporary package name change

* Hackily resolve the Intl.Segmenter issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't import files in lib/
2 participants