File tree Expand file tree Collapse file tree 3 files changed +39
-22
lines changed Expand file tree Collapse file tree 3 files changed +39
-22
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " rollup-plugin-node-externals" ,
3- "version" : " 3.0 .0" ,
3+ "version" : " 2.2 .0" ,
44 "description" : " Automatically declare NodeJS built-in modules and npm dependencies as 'external' in Rollup config" ,
55 "author" :
" Stephan Schreiber <[email protected] >" ,
66 "contributors" : [
3030 "url" : " https://github.com/Septh/rollup-plugin-node-externals"
3131 },
3232 "homepage" : " https://github.com/Septh/rollup-plugin-node-externals" ,
33- "type" : " module " ,
33+ "type" : " commonjs " ,
3434 "main" : " ./dist/cjs/index.js" ,
3535 "module" : " ./dist/esm/index.js" ,
3636 "exports" : {
37- "import " : " ./dist/cjs/index.js" ,
38- "require " : " ./dist/esm/index.js"
37+ "require " : " ./dist/cjs/index.js" ,
38+ "import " : " ./dist/esm/index.js"
3939 },
4040 "types" : " ./dist/index.d.ts" ,
4141 "files" : [
42- " dist/cjs/index.js" ,
43- " dist/esm/index.js" ,
44- " dist/index.d.ts" ,
42+ " dist" ,
4543 " README.md"
4644 ],
4745 "ava" : {
5553 "scripts" : {
5654 "build" : " rollup -c" ,
5755 "watch" : " rollup -cw" ,
58- "types" : " tsc src/index.ts --declaration --emitDeclarationOnly --outFile dist/index.d.ts --stripInternal" ,
5956 "test" : " ava" ,
6057 "watch-tests" : " ava -w" ,
6158 "clean" : " rimraf dist" ,
62- "prepublishOnly" : " npm run clean && npm run build && npm run types "
59+ "prepublishOnly" : " npm run clean && npm run build"
6360 },
6461 "dependencies" : {
6562 "find-up" : " ^6.2.0"
Original file line number Diff line number Diff line change @@ -8,22 +8,37 @@ import ts from 'rollup-plugin-ts'
88// @ts -ignore
99const pkg = createRequire ( import . meta. url ) ( './package.json' )
1010
11- /** @type { import('rollup').PluginImpl } */
12- const nodeColon = ( ) => {
11+ /**
12+ * A mini-plugin that resolves `node:` imports to their unprefixed equivalent.
13+ * @type { import('rollup').PluginImpl }
14+ */
15+ function nodeColon ( ) {
1316 return {
1417 name : 'node-colon' ,
1518
1619 resolveId ( id ) {
1720 for ( const scheme of [ 'node:' , 'nodejs:' ] ) {
1821 if ( id . startsWith ( scheme ) ) {
19- id = id . slice ( scheme . length )
20- return {
21- id,
22- external : external . includes ( id )
23- }
22+ return id . slice ( scheme . length )
2423 }
2524 }
26- return null
25+ }
26+ }
27+ }
28+
29+ /**
30+ * A mini-plugin that generates a package.json file next to the bundle.
31+ * @type { import('rollup').PluginImpl }
32+ */
33+ function emitModulePackageFile ( ) {
34+ return {
35+ name : 'emit-module-package-file' ,
36+ generateBundle ( ) {
37+ this . emitFile ( {
38+ type : 'asset' ,
39+ fileName : 'package.json' ,
40+ source : JSON . stringify ( { type : 'module' } , undefined , 2 )
41+ } )
2742 }
2843 }
2944}
@@ -35,13 +50,16 @@ const config = {
3550 {
3651 format : 'commonjs' ,
3752 file : pkg . main ,
38- exports : 'default ' ,
53+ exports : 'named ' ,
3954 sourcemap : false
4055 } ,
4156 {
4257 format : 'module' ,
4358 file : pkg . module ,
44- sourcemap : false
59+ sourcemap : false ,
60+ plugins : [
61+ emitModulePackageFile ( )
62+ ]
4563 } ,
4664 ] ,
4765 plugins : [
Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ export interface ExternalsOptions {
7070 )
7171
7272 // Build a function to filter out unwanted dependencies
73- const filterFn : ( dep : string ) => boolean = dep => ! exclude . some ( rx => rx . test ( dep ) )
73+ const filterFn = ( dep : string ) => ! exclude . some ( rx => rx . test ( dep ) )
7474
7575 // Filter NodeJS builtins
7676 const builtins = ( opts . builtins ? builtinModules : [ ] ) . filter ( filterFn )
@@ -118,10 +118,12 @@ export interface ExternalsOptions {
118118 }
119119 } ,
120120
121- resolveId ( source , importer ) {
121+ resolveId ( id , importer ) {
122122 // Return `false` if importee should be treated as an external module,
123123 // otherwise return `null` to let Rollup and other plugins handle it.
124- return importer && ! / \0 / . test ( source ) && externals . some ( deps => deps . test ( source ) ) ? false : null
124+ return importer && ! / \0 / . test ( id ) && externals . some ( deps => deps . test ( id ) ) && filterFn ( id )
125+ ? false
126+ : null
125127 }
126128 }
127129}
You can’t perform that action at this time.
0 commit comments