-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: esm and cjs #280
Closed
Closed
feat: esm and cjs #280
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mdonnalley
approved these changes
Oct 12, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QA:
- Added
@salesforce/kit@3.0.14-qa.1
to@oclif/plugin-test-cjs-1
and@oclif/plugin-test-esm-1
- Added this code to a command in each plugin:
import {Duration, sleep, env, parseJson, ensureArray} from '@salesforce/kit'
await sleep(Duration.seconds(1).milliseconds)
console.log(env.getString('PATH'))
console.log(parseJson('{"foo":"bar"}'))
console.log(ensureArray('foo'))
console.log(ensureArray(['foo']))
✅ Code compiled and ran in cjs plugin
✅ Code compiled and ran in esm plugin
there's parts of this that are probably valid (undoing lodash, etc) but the esm thing seems less useful than leaving that alone for now. was a good POC to see what it would take |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
DO NOT MERGE
exploration of dual-publish for libraries
@W-14154855@
Design
cjs publishes to
/cjs
, esm to/esm
. Usingexports
breaks projects who imported fromkit/lib
anyway (see cjs QA PR below) so no value in keeping the ambiguouslib
the
compile
step in wireit now runs the 2 compile jobs.Repo-specific Issues
lodash
lodash was "vendored" in from a custom build. It caused a lot of problems because of its default exports. Now it imports the various lodash functions needed for
external
. This let us get rid of the TS wrappers, the build step, etc. To avoid the cost of a larger node_modules folder (all of lodash)...BREAKING CHANGE: lodash methods are no longer re-exported. If you need lodash function, import them yourself!
Notes for dual-publishing other repos
type
,exports
,files
esm
and 'cjs' folders, similar tolib
"node-option": ["es-module-specifier-resolution=node", "loader=ts-node/esm"],
via mocharcTypeError: (0 , lodash_tonumber_1.default) is not a function at Env.getNumber (/Users/shane.mclaughlin/eng/kit/src/env.ts:239:27)
FWIW, I saw similar behavior in sfdx-core around some other modules with export = (jszip). This might cascade the requirement foresModuleInterop
across the whole codebaselodash-es
module and an option on lodash-cli to export es modules. They worked ok, but they caused problems for sfdx-core to understand. (Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/shane.mclaughlin/eng/kit/node_modules/lodash-es/tonumber.js from /Users/shane.mclaughlin/eng/kit/lib/env.js not supported. Instead change the require of tonumber.js in /Users/shane.mclaughlin/eng/kit/lib/env.js to a dynamic import() which is available in all CommonJS modules.
) I made some other adjustments to sfdx-core after going back to regular lodash, so maybe that would have eventually worked. 🤷🏻Testing
package available
@salesforce/kit@3.0.14-qa.0
pjson.files
is correct)cjs QA via forcedotcom/sfdx-core#950.
this pr has the breaking changes updates (ex: direct imports of lodash, etc)
esm QA
use the ESM version of oclif/plugin-update oclif/plugin-update#643
add kit as a depedendency and then start using it in the code.
for both, it should compile and tests should pass. Also check the dev experience--that you get types, jsdoc, etc