From 023ed0f01f2d2211962f042ea9290cda1e5734e2 Mon Sep 17 00:00:00 2001 From: dnalborczyk Date: Mon, 2 Jan 2023 04:23:47 -0500 Subject: [PATCH] Use Set and builtin-modules package (#4781) * Use Set and builtin-modules package * Ad comment * Make parameter readonly Co-authored-by: Lukas Taegert-Atkinson --- LICENSE.md | 17 ++++++++++ browser/LICENSE.md | 17 ++++++++++ package-lock.json | 1 + package.json | 1 + src/finalisers/shared/warnOnBuiltins.ts | 44 +++++++++++-------------- 5 files changed, 55 insertions(+), 25 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index d81631a597e..6a16c9ac0dd 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -186,6 +186,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 d66331904c5..905ecc9bcb8 100644 --- a/browser/LICENSE.md +++ b/browser/LICENSE.md @@ -117,6 +117,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 c7710d3fec0..f562c0478c2 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.6.0", diff --git a/package.json b/package.json index fb52dc5d0a9..e807efc2ece 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.6.0", diff --git a/src/finalisers/shared/warnOnBuiltins.ts b/src/finalisers/shared/warnOnBuiltins.ts index b3f20e50e63..51cd5e660bb 100644 --- a/src/finalisers/shared/warnOnBuiltins.ts +++ b/src/finalisers/shared/warnOnBuiltins.ts @@ -1,38 +1,32 @@ +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, + // TODO + // remove once builtin-modules includes PR: https://github.com/sindresorhus/builtin-modules/pull/17 + '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, - dependencies: ChunkDependency[] + dependencies: readonly ChunkDependency[] ): 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;