From 5e8141b8a1f58ab9117209eadbda75bd27b553b2 Mon Sep 17 00:00:00 2001 From: Daniel Nalborczyk Date: Fri, 30 Dec 2022 17:52:11 -0500 Subject: [PATCH 1/3] Use Set and builtin-modules package --- LICENSE.md | 17 +++++++++++ browser/LICENSE.md | 17 +++++++++++ package-lock.json | 1 + package.json | 1 + src/finalisers/shared/warnOnBuiltins.ts | 40 ++++++++++--------------- 5 files changed, 52 insertions(+), 24 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index 3da0f176acc..1fc625c267f 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -157,6 +157,23 @@ Repository: micromatch/braces --------------------------------------- +## builtin-modules +License: MIT +By: Sindre Sorhus +Repository: sindresorhus/builtin-modules + +> MIT License +> +> Copyright (c) Sindre Sorhus (https://sindresorhus.com) +> +> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +> +> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +--------------------------------------- + ## chokidar License: MIT By: Paul Miller, Elan Shanker diff --git a/browser/LICENSE.md b/browser/LICENSE.md index f0c9254ed4c..9d56345bebe 100644 --- a/browser/LICENSE.md +++ b/browser/LICENSE.md @@ -88,6 +88,23 @@ Repository: https://github.com/acornjs/acorn.git --------------------------------------- +## builtin-modules +License: MIT +By: Sindre Sorhus +Repository: sindresorhus/builtin-modules + +> MIT License +> +> Copyright (c) Sindre Sorhus (https://sindresorhus.com) +> +> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +> +> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +--------------------------------------- + ## flru License: MIT By: Luke Edwards diff --git a/package-lock.json b/package-lock.json index c613bffc0f0..64c99f445ed 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,6 +31,7 @@ "acorn-jsx": "^5.3.2", "acorn-walk": "^8.2.0", "buble": "^0.20.0", + "builtin-modules": "^3.3.0", "chokidar": "^3.5.3", "colorette": "^2.0.19", "concurrently": "^7.4.0", diff --git a/package.json b/package.json index 5dd88dea10e..b465db064fd 100644 --- a/package.json +++ b/package.json @@ -77,6 +77,7 @@ "acorn-jsx": "^5.3.2", "acorn-walk": "^8.2.0", "buble": "^0.20.0", + "builtin-modules": "^3.3.0", "chokidar": "^3.5.3", "colorette": "^2.0.19", "concurrently": "^7.4.0", diff --git a/src/finalisers/shared/warnOnBuiltins.ts b/src/finalisers/shared/warnOnBuiltins.ts index b3f20e50e63..578a83956d9 100644 --- a/src/finalisers/shared/warnOnBuiltins.ts +++ b/src/finalisers/shared/warnOnBuiltins.ts @@ -1,30 +1,22 @@ +import builtinModules from 'builtin-modules/static'; import type { ChunkDependency } from '../../Chunk'; import type { RollupWarning } from '../../rollup/types'; import { errorMissingNodeBuiltins } from '../../utils/error'; -const builtins = { - assert: 1, - buffer: 1, - console: 1, - constants: 1, - domain: 1, - events: 1, - http: 1, - https: 1, - os: 1, - path: 1, - process: 1, - punycode: 1, - querystring: 1, - stream: 1, - string_decoder: 1, - timers: 1, - tty: 1, - url: 1, - util: 1, - vm: 1, - zlib: 1 -}; +const nodeBuiltins: ReadonlySet = new Set([ + ...builtinModules, + 'assert/strict', + 'dns/promises', + 'fs/promises', + 'path/posix', + 'path/win32', + 'readline/promises', + 'stream/consumers', + 'stream/promises', + 'stream/web', + 'timers/promises', + 'util/types' +]); export default function warnOnBuiltins( warn: (warning: RollupWarning) => void, @@ -32,7 +24,7 @@ export default function warnOnBuiltins( ): void { const externalBuiltins = dependencies .map(({ importPath }) => importPath) - .filter(importPath => importPath in builtins || importPath.startsWith('node:')); + .filter(importPath => nodeBuiltins.has(importPath) || importPath.startsWith('node:')); if (externalBuiltins.length === 0) return; From a484cb37b37363652fcc7e95882294c69bc34b85 Mon Sep 17 00:00:00 2001 From: Daniel Nalborczyk Date: Fri, 30 Dec 2022 17:55:54 -0500 Subject: [PATCH 2/3] Ad comment --- src/finalisers/shared/warnOnBuiltins.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/finalisers/shared/warnOnBuiltins.ts b/src/finalisers/shared/warnOnBuiltins.ts index 578a83956d9..4f33698a41b 100644 --- a/src/finalisers/shared/warnOnBuiltins.ts +++ b/src/finalisers/shared/warnOnBuiltins.ts @@ -5,6 +5,8 @@ import { errorMissingNodeBuiltins } from '../../utils/error'; const nodeBuiltins: ReadonlySet = new Set([ ...builtinModules, + // TODO + // remove once builtin-modules includes PR: https://github.com/sindresorhus/builtin-modules/pull/17 'assert/strict', 'dns/promises', 'fs/promises', From 106177ae1260a8e9eaeb0b2806f53131fd065c5f Mon Sep 17 00:00:00 2001 From: Daniel Nalborczyk Date: Fri, 30 Dec 2022 17:57:20 -0500 Subject: [PATCH 3/3] Make parameter readonly --- src/finalisers/shared/warnOnBuiltins.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/finalisers/shared/warnOnBuiltins.ts b/src/finalisers/shared/warnOnBuiltins.ts index 4f33698a41b..51cd5e660bb 100644 --- a/src/finalisers/shared/warnOnBuiltins.ts +++ b/src/finalisers/shared/warnOnBuiltins.ts @@ -22,7 +22,7 @@ const nodeBuiltins: ReadonlySet = new Set([ export default function warnOnBuiltins( warn: (warning: RollupWarning) => void, - dependencies: ChunkDependency[] + dependencies: readonly ChunkDependency[] ): void { const externalBuiltins = dependencies .map(({ importPath }) => importPath)