Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Set and builtin-modules package #4781

Merged
merged 4 commits into from Jan 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions LICENSE.md
Expand Up @@ -186,6 +186,23 @@ Repository: micromatch/braces

---------------------------------------

## builtin-modules
License: MIT
By: Sindre Sorhus
Repository: sindresorhus/builtin-modules

> MIT License
>
> Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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
Expand Down
17 changes: 17 additions & 0 deletions browser/LICENSE.md
Expand Up @@ -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 <sindresorhus@gmail.com> (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
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -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",
Expand Down
44 changes: 19 additions & 25 deletions 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<string> = 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;

Expand Down