Skip to content
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: init nodejs-helpers package, add bypass-import-map, bypass-impo… #2053

Merged
merged 1 commit into from
Aug 18, 2023

Conversation

narzac
Copy link
Contributor

@narzac narzac commented Aug 2, 2023

…rt-map tasks, and run part of lion prepublish

What I did

  1. init nodejs-helpers package
  2. add bypass-import-map
  3. add bypass-export-map
  4. run part of lion prepublish

@changeset-bot
Copy link

changeset-bot bot commented Aug 2, 2023

🦋 Changeset detected

Latest commit: 122a481

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@lion/nodejs-helpers Patch
@lion/ui Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@CLAassistant
Copy link

CLAassistant commented Aug 2, 2023

CLA assistant check
All committers have signed the CLA.

@narzac narzac force-pushed the feat/bypass-export-map branch 10 times, most recently from bd0bf36 to 0f3f1a5 Compare August 16, 2023 08:43
@narzac narzac force-pushed the feat/bypass-export-map branch 2 times, most recently from 9b29e2c to d1d028c Compare August 16, 2023 15:53
};

describe('bypassExportMap simple export map case', async () => {
const packageDir = 'test-node/fixtures/simple-export-map';
Copy link
Member

@tlouisse tlouisse Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you consider using mock-fs (for readability and perf)?

Then we can do:

mockFs({
  '/simple-export-map/components/icon/xyz.js': "export x = () => 'bla';"
  // ... etc
})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I did consider mocking filesystem, however it is another layer of abstraction on top of the reality, which will make it less readable imo, and more of a complex solution. Of course, as you suggested we could still consider it, say for performance, and that would certainly be the case, if we were mocking timers and so on, yet performance wise the whole tests that access the filesystem are taking ~0.247 seconds to be precise.

To get the ~0.247, we can

First run the tests without the tests which uses the filesystem

rm -rf packages-node/nodejs-helpers/test-node/tasks/ && time npm run test -w packages-node/nodejs-helpers/

real 0m1.323s

And then, run it with them:
g checkout packages-node/nodejs-helpers/test-node/tasks/ && time npm run test -w packages-node/nodejs-helpers/

real 0m1.570s

Then the difference is ~0.247,, which is insignificant.

* @returns {Promise<any>}
*/
export const bypassImportMap = async (packageDir, options = {}) => {
const ignoredDirs = options.ignoredDirs || ['node_modules'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a future improvement: maybe we can leverage globby's gitignore option?

const exportMapValuePath = path.join(packageDir, exportMapValue);
const exportMapKeyPath = path.join(packageDir, exportMapKey);
const searchPattern = isDirectorySync(exportMapValuePath)
? path.join(exportMapValuePath, '**', '*.js')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some point, we might also support css import assertions. At that point, we can probably extract the generic export map resolver from providence and use it here as well.

@narzac narzac merged commit 296463d into master Aug 18, 2023
4 checks passed
@narzac narzac deleted the feat/bypass-export-map branch August 18, 2023 12:32
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.

3 participants