-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: handle named imports of builtin modules (#8338)
- Loading branch information
Showing
13 changed files
with
244 additions
and
39 deletions.
There are no files selected for viewing
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 was deleted.
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
18 changes: 18 additions & 0 deletions
18
playground/optimize-deps/dep-with-builtin-module-cjs/index.js
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,18 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
// NOTE: require destructure would error immediately because of how esbuild | ||
// compiles it. There's no way around it as it's direct property access, which | ||
// triggers the Proxy get trap. | ||
|
||
// access from default import | ||
try { | ||
path.join() | ||
} catch (e) { | ||
console.log('dep-with-builtin-module-cjs', e) | ||
} | ||
|
||
// access from function | ||
module.exports.read = () => { | ||
return fs.readFileSync('test') | ||
} |
6 changes: 6 additions & 0 deletions
6
playground/optimize-deps/dep-with-builtin-module-cjs/package.json
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,6 @@ | ||
{ | ||
"name": "dep-with-builtin-module-cjs", | ||
"private": true, | ||
"version": "0.0.0", | ||
"main": "index.js" | ||
} |
21 changes: 21 additions & 0 deletions
21
playground/optimize-deps/dep-with-builtin-module-esm/index.js
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,21 @@ | ||
import { readFileSync } from 'fs' | ||
import path from 'path' | ||
|
||
// access from named import | ||
try { | ||
readFileSync() | ||
} catch (e) { | ||
console.log('dep-with-builtin-module-esm', e) | ||
} | ||
|
||
// access from default import | ||
try { | ||
path.join() | ||
} catch (e) { | ||
console.log('dep-with-builtin-module-esm', e) | ||
} | ||
|
||
// access from function | ||
export function read() { | ||
return readFileSync('test') | ||
} |
7 changes: 7 additions & 0 deletions
7
playground/optimize-deps/dep-with-builtin-module-esm/package.json
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": "dep-with-builtin-module-esm", | ||
"private": true, | ||
"version": "0.0.0", | ||
"main": "index.js", | ||
"type": "module" | ||
} |
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
Oops, something went wrong.