This repository has been archived by the owner on May 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
feat: replace precinct with esbuild #659
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1b90c9b
refactor: replace precinct with esbuild
eduardoboucas a2aa95f
refactor: add feature flag
eduardoboucas 61e0cfb
fix: add feature flags object
eduardoboucas f476a99
refactor: turn feature flag off by default
eduardoboucas ce73ec9
chore: add test
eduardoboucas 32af5e3
refactor: use intermediate variable
eduardoboucas 1390461
refactor: await `safeUnlink` call
eduardoboucas 403aa50
Merge branch 'main' into feat/remove-precinct
kodiakhq[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const esbuild = require('@netlify/esbuild') | ||
const isBuiltinModule = require('is-builtin-module') | ||
const { tmpName } = require('tmp-promise') | ||
|
||
const { safeUnlink } = require('../../utils/fs') | ||
|
||
const getListImportsPlugin = ({ imports, path }) => ({ | ||
name: 'list-imports', | ||
setup(build) { | ||
build.onResolve({ filter: /.*/ }, (args) => { | ||
const isEntryPoint = args.path === path | ||
const isImport = !isEntryPoint && !isBuiltinModule(args.path) | ||
|
||
if (isImport) { | ||
imports.add(args.path) | ||
} | ||
|
||
return { | ||
namespace: 'list-imports', | ||
external: isImport, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By setting a path as |
||
} | ||
}) | ||
}, | ||
}) | ||
|
||
const listImports = async ({ path }) => { | ||
// We're not interested in the output that esbuild generates, we're just | ||
// using it for its parsing capabilities in order to find import/require | ||
// statements. However, if we don't give esbuild a path in `outfile`, it | ||
// will pipe the output to stdout, which we also don't want. So we create | ||
// a temporary file to serve as the esbuild output and then get rid of it | ||
// when we're done. | ||
const targetPath = await tmpName() | ||
const imports = new Set() | ||
|
||
try { | ||
await esbuild.build({ | ||
entryPoints: [path], | ||
bundle: true, | ||
outfile: targetPath, | ||
platform: 'node', | ||
plugins: [getListImportsPlugin({ imports, path })], | ||
}) | ||
} finally { | ||
safeUnlink(targetPath) | ||
eduardoboucas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
return [...imports] | ||
} | ||
|
||
module.exports = { listImports } |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const mock = require('@netlify/mock-package') | ||
const stack = require('@netlify/mock-package/stack') | ||
|
||
module.exports = { mock, stack } |
3 changes: 3 additions & 0 deletions
3
tests/fixtures/local-node-module-deep-require/node_modules/@netlify/mock-package/index.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
...s/fixtures/local-node-module-deep-require/node_modules/@netlify/mock-package/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
tests/fixtures/local-node-module-deep-require/node_modules/@netlify/mock-package/stack.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "local-node-module", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"@netlify/mock-package": "1.0.0" | ||
} | ||
} |
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
Oops, something went wrong.
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.
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.
We'll use this feature flag to roll this out progressively. Once the rollout is complete, we can remove
precinct
entirely.