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

[v3.0] Use node: prefix for builtin imports #4596

Merged
merged 1 commit into from Aug 11, 2022
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
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -76,7 +76,7 @@ For example, with CommonJS, the _entire tool or library must be imported_.

```js
// import the entire utils object with CommonJS
var utils = require('utils');
var utils = require('node:utils');
var query = 'Rollup';
// use the ajax method of the utils object
utils.ajax('https://api.example.com?search=' + query).then(handleResponse);
Expand All @@ -86,7 +86,7 @@ But with ES modules, instead of importing the whole `utils` object, we can just

```js
// import the ajax function with an ES import statement
import { ajax } from 'utils';
import { ajax } from 'node:utils';
var query = 'Rollup';
// call the ajax function
ajax('https://api.example.com?search=' + query).then(handleResponse);
Expand Down
4 changes: 2 additions & 2 deletions build-plugins/add-cli-entry.ts
@@ -1,5 +1,5 @@
import { chmod } from 'fs/promises';
import { resolve } from 'path';
import { chmod } from 'node:fs/promises';
import { resolve } from 'node:path';
import MagicString from 'magic-string';
import type { Plugin } from 'rollup';

Expand Down
2 changes: 1 addition & 1 deletion build-plugins/copy-types.ts
@@ -1,4 +1,4 @@
import { resolve } from 'path';
import { resolve } from 'node:path';
import { readFile } from 'fs-extra';
import type { Plugin } from 'rollup';

Expand Down
4 changes: 2 additions & 2 deletions build-plugins/generate-license-file.ts
@@ -1,5 +1,5 @@
import { promises as fs } from 'fs';
import { join } from 'path';
import { promises as fs } from 'node:fs';
import { join } from 'node:path';
import type { PluginImpl } from 'rollup';
import license, { type Dependency, type Person } from 'rollup-plugin-license';

Expand Down
6 changes: 3 additions & 3 deletions build-plugins/get-banner.ts
@@ -1,6 +1,6 @@
import { exec } from 'child_process';
import { env } from 'process';
import { promisify } from 'util';
import { exec } from 'node:child_process';
import { env } from 'node:process';
import { promisify } from 'node:util';
import { version } from '../package.json';

const execPromise = promisify(exec);
Expand Down
2 changes: 1 addition & 1 deletion build-plugins/replace-browser-modules.ts
@@ -1,4 +1,4 @@
import { dirname, join, resolve } from 'path';
import { dirname, join, resolve } from 'node:path';
import type { Plugin } from 'rollup';

const resolutions = {
Expand Down
2 changes: 1 addition & 1 deletion cli/cli.ts
@@ -1,4 +1,4 @@
import process from 'process';
import process from 'node:process';
import help from 'help.md';
import { version } from 'package.json';
import argParser from 'yargs-parser';
Expand Down
2 changes: 1 addition & 1 deletion cli/logging.ts
@@ -1,4 +1,4 @@
import process from 'process';
import process from 'node:process';
import type { RollupError } from '../src/rollup/types';
import { bold, cyan, dim, red } from '../src/utils/colors';
import relativeId from '../src/utils/relativeId';
Expand Down
2 changes: 1 addition & 1 deletion cli/run/build.ts
@@ -1,4 +1,4 @@
import process from 'process';
import process from 'node:process';
import ms from 'pretty-ms';
import { rollup } from '../../src/node-entry';
import type { MergedRollupOptions } from '../../src/rollup/types';
Expand Down
4 changes: 2 additions & 2 deletions cli/run/commandPlugins.ts
@@ -1,5 +1,5 @@
import { resolve } from 'path';
import { pathToFileURL } from 'url';
import { resolve } from 'node:path';
import { pathToFileURL } from 'node:url';
import type { InputOptions } from '../../src/rollup/types';
import { stdinPlugin } from './stdin';
import { waitForInputPlugin } from './waitForInput';
Expand Down
6 changes: 3 additions & 3 deletions cli/run/getConfigPath.ts
@@ -1,6 +1,6 @@
import { promises as fs } from 'fs';
import { resolve } from 'path';
import { cwd } from 'process';
import { promises as fs } from 'node:fs';
import { resolve } from 'node:path';
import { cwd } from 'node:process';
import { errMissingExternalConfig } from '../../src/utils/error';
import { handleError } from '../logging';

Expand Down
2 changes: 1 addition & 1 deletion cli/run/index.ts
@@ -1,4 +1,4 @@
import { env } from 'process';
import { env } from 'node:process';
import type { MergedRollupOptions } from '../../src/rollup/types';
import { errDuplicateImportOptions, errFailAfterWarnings } from '../../src/utils/error';
import { isWatchEnabled } from '../../src/utils/options/mergeOptions';
Expand Down
4 changes: 2 additions & 2 deletions cli/run/loadConfigFile.ts
@@ -1,5 +1,5 @@
import { extname, isAbsolute } from 'path';
import { pathToFileURL } from 'url';
import { extname, isAbsolute } from 'node:path';
import { pathToFileURL } from 'node:url';
import getPackageType from 'get-package-type';
import * as rollup from '../../src/node-entry';
import type { MergedRollupOptions } from '../../src/rollup/types';
Expand Down
2 changes: 1 addition & 1 deletion cli/run/loadConfigFromCommand.ts
@@ -1,4 +1,4 @@
import process from 'process';
import process from 'node:process';
import type { MergedRollupOptions } from '../../src/rollup/types';
import { mergeOptions } from '../../src/utils/options/mergeOptions';
import batchWarnings, { type BatchWarnings } from './batchWarnings';
Expand Down
2 changes: 1 addition & 1 deletion cli/run/stdin.ts
@@ -1,4 +1,4 @@
import process from 'process';
import process from 'node:process';
import type { Plugin } from '../../src/rollup/types';

export const stdinName = '-';
Expand Down
4 changes: 2 additions & 2 deletions cli/run/watch-cli.ts
@@ -1,5 +1,5 @@
import { promises as fs, type FSWatcher } from 'fs';
import process from 'process';
import { promises as fs, type FSWatcher } from 'node:fs';
import process from 'node:process';
import chokidar from 'chokidar';
import dateTime from 'date-time';
import ms from 'pretty-ms';
Expand Down
2 changes: 1 addition & 1 deletion cli/run/watchHooks.ts
@@ -1,4 +1,4 @@
import { execSync } from 'child_process';
import { execSync } from 'node:child_process';
import type { RollupWatchHooks } from '../../src/rollup/types';
import { bold, cyan } from '../../src/utils/colors';
import { stderr } from '../logging';
Expand Down
6 changes: 3 additions & 3 deletions docs/01-command-line-reference.md
Expand Up @@ -284,7 +284,7 @@ With CommonJS files, people often use `__dirname` to access the current director

```js
// rollup.config.js
import { fileURLToPath } from 'url'
import { fileURLToPath } from 'node:url'

export default {
...,
Expand All @@ -311,7 +311,7 @@ It can be useful to import your package file to e.g. mark your dependencies as "
- For older Node versions, you can use `createRequire`

```js
import { createRequire } from 'module';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const pkg = require('./package.json');

Expand All @@ -322,7 +322,7 @@ It can be useful to import your package file to e.g. mark your dependencies as "

```js
// rollup.config.mjs
import { readFileSync } from 'fs';
import { readFileSync } from 'node:fs';

// Use import.meta.url to make the path relative to the current source file instead of process.cwd()
// For more info: https://nodejs.org/docs/latest-v16.x/api/esm.html#importmetaurl
Expand Down
2 changes: 1 addition & 1 deletion docs/02-javascript-api.md
Expand Up @@ -263,7 +263,7 @@ In order to aid in generating such a config, rollup exposes the helper it uses t

```js
const { loadConfigFile } = require('rollup/loadConfigFile');
const path = require('path');
const path = require('node:path');
const rollup = require('rollup');

// load the config file next to the current script;
Expand Down
10 changes: 5 additions & 5 deletions docs/999-big-list-of-options.md
Expand Up @@ -15,7 +15,7 @@ Either a function that takes an `id` and returns `true` (external) or `false` (n

```js
// rollup.config.js
import { fileURLToPath } from 'url'
import { fileURLToPath } from 'node:url'

export default {
...,
Expand Down Expand Up @@ -95,8 +95,8 @@ If you want to convert a set of file to another format while maintaining the fil

```js
import glob from 'glob';
import path from 'path';
import { fileURLToPath } from 'url';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

export default {
input: Object.fromEntries(
Expand Down Expand Up @@ -208,7 +208,7 @@ To tell Rollup that a local file should be replaced by a global variable, use an

```js
// rollup.config.js
import { fileURLToPath } from 'url'
import { fileURLToPath } from 'node:url'
const externalId = fileURLToPath(new URL('src/some-local-file-that-should-not-be-bundled.js', import.meta.url))

export default {
Expand Down Expand Up @@ -1132,7 +1132,7 @@ Type: `(relativeSourcePath: string, sourcemapPath: string) => string`
A transformation to apply to each path in a sourcemap. `relativeSourcePath` is a relative path from the generated `.map` file to the corresponding source file while `sourcemapPath` is the fully resolved path of the generated sourcemap file.

```js
import path from 'path';
import path from 'node:path';
export default {
input: 'src/main',
output: [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -125,7 +125,7 @@
"dist/es/package.json"
],
"engines": {
"node": ">=14.0.0",
"node": ">=14.13.1",
"npm": ">=8.0.0"
},
"exports": {
Expand Down
4 changes: 2 additions & 2 deletions rollup.config.ts
@@ -1,5 +1,5 @@
import { resolve } from 'path';
import { fileURLToPath } from 'url';
import { resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import alias from '@rollup/plugin-alias';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
Expand Down
2 changes: 1 addition & 1 deletion scripts/release.js
@@ -1,8 +1,8 @@
#!/usr/bin/env node

import { readFile, writeFile } from 'fs/promises';
import { chdir, exit } from 'node:process';
import { fileURLToPath } from 'node:url';
import { chdir, exit } from 'process';
import GitHub from 'github-api';
import inquirer from 'inquirer';
import semverInc from 'semver/functions/inc.js';
Expand Down
44 changes: 22 additions & 22 deletions src/finalisers/shared/warnOnBuiltins.ts
Expand Up @@ -3,27 +3,27 @@ import type { RollupWarning } from '../../rollup/types';
import { errMissingNodeBuiltins } from '../../utils/error';

const builtins = {
assert: true,
buffer: true,
console: true,
constants: true,
domain: true,
events: true,
http: true,
https: true,
os: true,
path: true,
process: true,
punycode: true,
querystring: true,
stream: true,
string_decoder: true,
timers: true,
tty: true,
url: true,
util: true,
vm: true,
zlib: true
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
};

export default function warnOnBuiltins(
Expand All @@ -32,7 +32,7 @@ export default function warnOnBuiltins(
): void {
const externalBuiltins = dependencies
.map(({ importPath }) => importPath)
.filter(importPath => importPath in builtins);
.filter(importPath => importPath in builtins || importPath.startsWith('node:'));

if (!externalBuiltins.length) return;

Expand Down
2 changes: 1 addition & 1 deletion src/utils/colors.ts
@@ -1,4 +1,4 @@
import { env } from 'process';
import { env } from 'node:process';
import { createColors } from 'colorette';

// @see https://no-color.org
Expand Down
2 changes: 1 addition & 1 deletion src/utils/crypto.ts
@@ -1,3 +1,3 @@
import { createHash as cryptoCreateHash, type Hash } from 'crypto';
import { createHash as cryptoCreateHash, type Hash } from 'node:crypto';

export const createHash = (): Hash => cryptoCreateHash('sha256');
2 changes: 1 addition & 1 deletion src/utils/fs.ts
@@ -1 +1 @@
export * from 'fs';
export * from 'node:fs';
4 changes: 2 additions & 2 deletions src/utils/hookActions.ts
@@ -1,5 +1,5 @@
import { EventEmitter } from 'events';
import process from 'process';
import { EventEmitter } from 'node:events';
import process from 'node:process';
import { HookAction, PluginDriver } from './PluginDriver';

function formatAction([pluginName, hookName, args]: HookAction): string {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/path.ts
Expand Up @@ -15,4 +15,4 @@ export function normalize(path: string): string {
return path.replace(BACKSLASH_REGEX, '/');
}

export { basename, dirname, extname, relative, resolve } from 'path';
export { basename, dirname, extname, relative, resolve } from 'node:path';
2 changes: 1 addition & 1 deletion src/utils/performance.ts
@@ -1 +1 @@
export { performance as default } from 'perf_hooks';
export { performance as default } from 'node:perf_hooks';
2 changes: 1 addition & 1 deletion src/utils/process.ts
@@ -1 +1 @@
export { default } from 'process';
export { default } from 'node:process';
2 changes: 1 addition & 1 deletion src/watch/WatchEmitter.ts
@@ -1,4 +1,4 @@
import { EventEmitter } from 'events';
import { EventEmitter } from 'node:events';

type PromiseReturn<T extends (...args: any) => any> = (
...args: Parameters<T>
Expand Down
2 changes: 1 addition & 1 deletion src/watch/fileWatcher.ts
@@ -1,4 +1,4 @@
import { platform } from 'os';
import { platform } from 'node:os';
import chokidar, { type FSWatcher } from 'chokidar';
import type { ChangeEvent, ChokidarOptions } from '../rollup/types';
import type { Task } from './watch';
Expand Down
4 changes: 2 additions & 2 deletions src/watch/watch.ts
@@ -1,5 +1,5 @@
import { resolve } from 'path';
import process from 'process';
import { resolve } from 'node:path';
import process from 'node:process';
import { createFilter } from '@rollup/pluginutils';
import { rollupInternal } from '../rollup/rollup';
import type {
Expand Down
2 changes: 1 addition & 1 deletion test/browser/index.js
Expand Up @@ -3,7 +3,7 @@
// available globally in all supported platforms. [currently global for node.js v16+].
global.performance = require('perf_hooks').performance;

const { basename, resolve } = require('path');
const { basename, resolve } = require('node:path');
const fixturify = require('fixturify');
const { rollup } = require('../../browser/dist/rollup.browser.js');
const { assertFilesAreEqual, runTestSuiteWithSamples, compareError } = require('../utils.js');
Expand Down
6 changes: 3 additions & 3 deletions test/chunking-form/index.js
@@ -1,5 +1,5 @@
const { basename, resolve } = require('path');
const { chdir } = require('process');
const { basename, resolve } = require('node:path');
const { chdir } = require('node:process');
const { rollup } = require('../../dist/rollup');
const { runTestSuiteWithSamples, assertDirectoriesAreEqual } = require('../utils.js');

Expand Down Expand Up @@ -63,7 +63,7 @@ async function generateAndTestBundle(bundle, outputOptions, expectedDir, config)
if (outputOptions.format === 'amd' && config.runAmd) {
try {
const exports = await new Promise((resolve, reject) => {
global.assert = require('assert');
global.assert = require('node:assert');
const requirejs = require('requirejs');
requirejs.config({ baseUrl: outputOptions.dir });
requirejs([config.nestedDir ? `${config.nestedDir}/main` : 'main'], resolve, reject);
Expand Down
10 changes: 5 additions & 5 deletions test/cli/index.js
@@ -1,8 +1,8 @@
const assert = require('assert');
const { exec } = require('child_process');
const { existsSync, readFileSync } = require('fs');
const { basename, resolve, sep } = require('path');
const process = require('process');
const assert = require('node:assert');
const { exec } = require('node:child_process');
const { existsSync, readFileSync } = require('node:fs');
const { basename, resolve, sep } = require('node:path');
const process = require('node:process');
const { copySync, removeSync, statSync } = require('fs-extra');
const {
normaliseOutput,
Expand Down