Skip to content

Commit

Permalink
nit: use node: prefix everywhere (#7692)
Browse files Browse the repository at this point in the history
* nit: use `node:` prefix everywhere

* nit: fs/promises too

* test: workaround issue in node builtin detection
  • Loading branch information
Princesseuh authored Jul 18, 2023
1 parent cc0f81c commit f14e480
Show file tree
Hide file tree
Showing 150 changed files with 283 additions and 286 deletions.
8 changes: 4 additions & 4 deletions .github/scripts/bundle-size.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { build } from 'esbuild';
import { existsSync } from 'fs';
import { existsSync } from 'node:fs';

const CLIENT_RUNTIME_PATH = 'packages/astro/src/runtime/client/';

Expand Down Expand Up @@ -27,13 +27,13 @@ export default async function checkBundleSize({ github, context }) {
return file.filename.startsWith(CLIENT_RUNTIME_PATH) && file.status !== 'removed'
});
if (clientRuntimeFiles.length === 0) return;

const table = [
'| File | Old Size | New Size | Change |',
'| ---- | -------- | -------- | ------ |',
];
const output = await bundle(clientRuntimeFiles);

for (let [filename, { oldSize, newSize, sourceFile }] of Object.entries(output)) {
filename = ['idle', 'load', 'media', 'only', 'visible'].includes(filename) ? `client:${filename}` : filename;
const prefix = (newSize - oldSize) === 0 ? '' : (newSize - oldSize) > 0 ? '+ ' : '- ';
Expand All @@ -60,7 +60,7 @@ ${table.join('\n')}`,
}

async function bundle(files) {

const { metafile } = await build({
entryPoints: [...files.map(({ filename }) => filename), ...files.map(({ filename }) => `main/${filename}`).filter(f => existsSync(f))],
bundle: true,
Expand Down
2 changes: 1 addition & 1 deletion benchmark/bench/cli-startup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fileURLToPath } from 'url';
import { fileURLToPath } from 'node:url';
import { execaCommand } from 'execa';
import { markdownTable } from 'markdown-table';
import { astroBin, calculateStat } from './_util.js';
Expand Down
4 changes: 2 additions & 2 deletions benchmark/bench/memory.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs/promises';
import { fileURLToPath } from 'url';
import { execaCommand } from 'execa';
import { markdownTable } from 'markdown-table';
import fs from 'node:fs/promises';
import { fileURLToPath } from 'node:url';
import { astroBin } from './_util.js';

/** @typedef {Record<string, import('../../packages/astro/src/core/config/timer').Stat>} AstroTimerStat */
Expand Down
12 changes: 6 additions & 6 deletions benchmark/bench/render.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import fs from 'fs/promises';
import http from 'http';
import path from 'path';
import { fileURLToPath } from 'url';
import { execaCommand } from 'execa';
import { waitUntilBusy } from 'port-authority';
import { markdownTable } from 'markdown-table';
import { renderFiles } from '../make-project/render-default.js';
import fs from 'node:fs/promises';
import http from 'node:http';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { waitUntilBusy } from 'port-authority';
import { calculateStat } from '../make-project/_util.js';
import { renderFiles } from '../make-project/render-default.js';
import { astroBin } from './_util.js';

const port = 4322;
Expand Down
6 changes: 3 additions & 3 deletions benchmark/bench/server-stress.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import fs from 'fs/promises';
import { fileURLToPath } from 'url';
import autocannon from 'autocannon';
import { execaCommand } from 'execa';
import { waitUntilBusy } from 'port-authority';
import { markdownTable } from 'markdown-table';
import fs from 'node:fs/promises';
import { fileURLToPath } from 'node:url';
import { waitUntilBusy } from 'port-authority';
import pb from 'pretty-bytes';
import { astroBin } from './_util.js';

Expand Down
6 changes: 3 additions & 3 deletions benchmark/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs/promises';
import path from 'path';
import { pathToFileURL } from 'url';
import mri from 'mri';
import fs from 'node:fs/promises';
import path from 'node:path';
import { pathToFileURL } from 'node:url';

const args = mri(process.argv.slice(2));

Expand Down
2 changes: 1 addition & 1 deletion benchmark/make-project/memory-default.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from 'fs/promises';
import fs from 'node:fs/promises';
import { loremIpsum } from './_util.js';

/**
Expand Down
2 changes: 1 addition & 1 deletion benchmark/make-project/render-default.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from 'fs/promises';
import fs from 'node:fs/promises';
import { loremIpsumHtml, loremIpsumMd } from './_util.js';

// Map of files to be generated and tested for rendering.
Expand Down
2 changes: 1 addition & 1 deletion benchmark/make-project/server-stress-default.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from 'fs/promises';
import fs from 'node:fs/promises';
import { loremIpsum } from './_util.js';

/**
Expand Down
2 changes: 1 addition & 1 deletion benchmark/packages/timer/src/preview.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CreatePreviewServer } from 'astro';
import { createServer } from 'http';
import { createServer } from 'node:http';
import enableDestroy from 'server-destroy';

const preview: CreatePreviewServer = async function ({ serverEntrypoint, host, port }) {
Expand Down
2 changes: 1 addition & 1 deletion benchmark/packages/timer/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { polyfill } from '@astrojs/webapi';
import type { SSRManifest } from 'astro';
import { NodeApp } from 'astro/app/node';
import type { IncomingMessage, ServerResponse } from 'http';
import type { IncomingMessage, ServerResponse } from 'node:http';

polyfill(globalThis, {
exclude: 'window document',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineConfig } from 'astro/config';
import react from "@astrojs/react";
import { fileURLToPath } from 'url';
import { fileURLToPath } from 'node:url';

export default defineConfig({
integrations: [astroClientClickDirective(), astroClientPasswordDirective(), react()],
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/fixtures/tailwindcss/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineConfig } from 'astro/config';
import tailwind from '@astrojs/tailwind';
import { fileURLToPath } from 'url';
import { fileURLToPath } from 'node:url';

// https://astro.build/config
export default defineConfig({
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/fixtures/tailwindcss/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const path = require('path');
const path = require('node:path');

module.exports = {
content: [path.join(__dirname, 'src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}')],
Expand Down
6 changes: 3 additions & 3 deletions packages/astro/e2e/test-utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs/promises';
import path from 'path';
import { test as testBase, expect } from '@playwright/test';
import { expect, test as testBase } from '@playwright/test';
import fs from 'node:fs/promises';
import path from 'node:path';
import { loadFixture as baseLoadFixture } from '../test/test-utils.js';

export const isWindows = process.platform === 'win32';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/performance/content-benchmark.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-console */

import { fileURLToPath } from 'url';
import { fileURLToPath } from 'node:url';
import { loadFixture } from '../test/test-utils.js';
import { generatePosts } from './scripts/generate-posts.mjs';
import yargs from 'yargs-parser';
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/performance/scripts/generate-posts.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs';
import path from 'path';
import fs from 'node:fs';
import path from 'node:path';

const NUM_POSTS = 10;
const POSTS_DIR = './src/content/posts.generated';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/scripts/shiki-gen-languages.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from 'fs';
import fs from 'node:fs';

const dir = await fs.promises.readdir('packages/astro/node_modules/shiki/languages/');

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/scripts/shiki-gen-themes.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from 'fs';
import fs from 'node:fs';

const dir = await fs.promises.readdir('packages/astro/node_modules/shiki/themes/');

Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import type {
ShikiConfig,
} from '@astrojs/markdown-remark';
import type * as babel from '@babel/core';
import type { OutgoingHttpHeaders } from 'http';
import type { AddressInfo } from 'net';
import type { OutgoingHttpHeaders } from 'node:http';
import type { AddressInfo } from 'node:net';
import type * as rollup from 'rollup';
import type { TsConfigJson } from 'tsconfig-resolver';
import type * as vite from 'vite';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ var Module = (function () {
var nodePath
if (ENVIRONMENT_IS_NODE) {
if (ENVIRONMENT_IS_WORKER) {
scriptDirectory = require('path').dirname(scriptDirectory) + '/'
scriptDirectory = require('node:path').dirname(scriptDirectory) + '/'
} else {
scriptDirectory = dirname(getModuleURL(import.meta.url)) + '/'
}
read_ = function shell_read(filename, binary) {
if (!nodeFS) nodeFS = require('fs')
if (!nodePath) nodePath = require('path')
if (!nodeFS) nodeFS = require('node:fs')
if (!nodePath) nodePath = require('node:path')
filename = nodePath['normalize'](filename)
return nodeFS['readFileSync'](filename, binary ? null : 'utf8')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ var Module = (function () {
var nodePath
if (ENVIRONMENT_IS_NODE) {
if (ENVIRONMENT_IS_WORKER) {
scriptDirectory = require('path').dirname(scriptDirectory) + '/'
scriptDirectory = require('node:path').dirname(scriptDirectory) + '/'
} else {
scriptDirectory = dirname(getModuleURL(import.meta.url)) + '/'
}
read_ = function shell_read(filename, binary) {
if (!nodeFS) nodeFS = require('fs')
if (!nodePath) nodePath = require('path')
if (!nodeFS) nodeFS = require('node:fs')
if (!nodePath) nodePath = require('node:path')
filename = nodePath['normalize'](filename)
return nodeFS['readFileSync'](filename, binary ? null : 'utf8')
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { cpus } from 'node:os';
import { fileURLToPath } from 'node:url';
import { isMainThread } from 'node:worker_threads';
import { cpus } from 'os';
import { fileURLToPath } from 'url';
import type { ImageOutputFormat } from '../../../types.js';
import { getModuleURL } from './emscripten-utils.js';
import type { Operation } from './image.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ var Module = (function () {
var nodePath
if (ENVIRONMENT_IS_NODE) {
if (ENVIRONMENT_IS_WORKER) {
scriptDirectory = require('path').dirname(scriptDirectory) + '/'
scriptDirectory = require('node:path').dirname(scriptDirectory) + '/'
} else {
scriptDirectory = dirname(getModuleURL(import.meta.url)) + '/'
}
read_ = function shell_read(filename, binary) {
if (!nodeFS) nodeFS = require('fs')
if (!nodePath) nodePath = require('path')
if (!nodeFS) nodeFS = require('node:fs')
if (!nodePath) nodePath = require('node:path')
filename = nodePath['normalize'](filename)
return nodeFS['readFileSync'](filename, binary ? null : 'utf8')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ var Module = (function () {
var nodePath
if (ENVIRONMENT_IS_NODE) {
if (ENVIRONMENT_IS_WORKER) {
scriptDirectory = require('path').dirname(scriptDirectory) + '/'
scriptDirectory = require('node:path').dirname(scriptDirectory) + '/'
} else {
scriptDirectory = dirname(getModuleURL(import.meta.url)) + '/'
}
read_ = function shell_read(filename, binary) {
if (!nodeFS) nodeFS = require('fs')
if (!nodePath) nodePath = require('path')
if (!nodeFS) nodeFS = require('node:fs')
if (!nodePath) nodePath = require('node:path')
filename = nodePath['normalize'](filename)
return nodeFS['readFileSync'](filename, binary ? null : 'utf8')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ var Module = (function () {
var nodePath
if (ENVIRONMENT_IS_NODE) {
if (ENVIRONMENT_IS_WORKER) {
scriptDirectory = require('path').dirname(scriptDirectory) + '/'
scriptDirectory = require('node:path').dirname(scriptDirectory) + '/'
} else {
scriptDirectory = dirname(getModuleURL(import.meta.url)) + '/'
}
read_ = function shell_read(filename, binary) {
if (!nodeFS) nodeFS = require('fs')
if (!nodePath) nodePath = require('path')
if (!nodeFS) nodeFS = require('node:fs')
if (!nodePath) nodePath = require('node:path')
filename = nodePath['normalize'](filename)
return nodeFS['readFileSync'](filename, binary ? null : 'utf8')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ var Module = (function () {
var nodePath
if (ENVIRONMENT_IS_NODE) {
if (ENVIRONMENT_IS_WORKER) {
scriptDirectory = require('path').dirname(scriptDirectory) + '/'
scriptDirectory = require('node:path').dirname(scriptDirectory) + '/'
} else {
scriptDirectory = dirname(getModuleURL(import.meta.url)) + '/'
}
read_ = function shell_read(filename, binary) {
if (!nodeFS) nodeFS = require('fs')
if (!nodePath) nodePath = require('path')
if (!nodeFS) nodeFS = require('node:fs')
if (!nodePath) nodePath = require('node:path')
filename = nodePath['normalize'](filename)
return nodeFS['readFileSync'](filename, binary ? null : 'utf8')
}
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/assets/utils/transformToPath.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { basename, extname } from 'path';
import { basename, extname } from 'node:path';
import { removeQueryString } from '../../core/path.js';
import { shorthash } from '../../runtime/server/shorthash.js';
import { isESMImportedImage } from '../internal.js';
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/assets/vendor/image-size/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fs from "fs";
import * as path from "path";
import * as fs from "node:fs";
import * as path from "node:path";
import Queue from "../queue/queue.js";
import { detector } from "./detector.js";
import { typeHandlers, type imageType } from "./types.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/assets/vendor/image-size/types/tiff.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// based on https://www.compix.com/fileformattif.htm
// TO-DO: support big-endian as well
import * as fs from 'fs'
import * as fs from 'node:fs'
import { readUInt } from '../readUInt.js'
import type { IImage } from './interface'

Expand Down
6 changes: 3 additions & 3 deletions packages/astro/src/cli/add/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import boxen from 'boxen';
import { diffWords } from 'diff';
import { execa } from 'execa';
import fsMod, { existsSync, promises as fs } from 'fs';
import { bold, cyan, dim, green, magenta, red, yellow } from 'kleur/colors';
import fsMod, { existsSync, promises as fs } from 'node:fs';
import path from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import ora from 'ora';
import path from 'path';
import preferredPM from 'preferred-pm';
import prompts from 'prompts';
import { fileURLToPath, pathToFileURL } from 'url';
import type yargs from 'yargs-parser';
import { loadTSConfig, resolveConfigPath } from '../../core/config/index.js';
import {
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/cli/check/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import {
} from '@astrojs/language-server';
import type { FSWatcher } from 'chokidar';
import glob from 'fast-glob';
import fs from 'fs';
import { bold, dim, red, yellow } from 'kleur/colors';
import { createRequire } from 'module';
import fs from 'node:fs';
import { join } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import ora from 'ora';
import { fileURLToPath, pathToFileURL } from 'url';
import type { Arguments as Flags } from 'yargs-parser';
import type { AstroSettings } from '../../@types/astro';
import type { LogOptions } from '../../core/logger/core.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/cli/check/print.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
yellow,
} from 'kleur/colors';
import stringWidth from 'string-width';
import { fileURLToPath } from 'url';
import { fileURLToPath } from 'node:url';

export function printDiagnostic(filePath: string, text: string, diag: Diagnostic): string {
let result = [];
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/cli/dev/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from 'fs';
import fs from 'node:fs';
import type yargs from 'yargs-parser';
import { resolveConfigPath, resolveFlags } from '../../core/config/index.js';
import devServer from '../../core/dev/index.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/cli/load-settings.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-console */
import fs from 'fs';
import * as colors from 'kleur/colors';
import fs from 'node:fs';
import type { Arguments as Flags } from 'yargs-parser';
import { ZodError } from 'zod';
import { createSettings, openConfig, resolveConfigPath } from '../core/config/index.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/cli/sync/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from 'fs';
import fs from 'node:fs';
import type yargs from 'yargs-parser';
import type { LogOptions } from '../../core/logger/core.js';
import { syncCli } from '../../core/sync/index.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function getViteConfig(inlineConfig: UserConfig) {
{ runHookConfigSetup, runHookConfigDone },
{ astroContentListenPlugin },
] = await Promise.all([
import('fs'),
import('node:fs'),
import('vite'),
import('../core/logger/node.js'),
import('../core/config/index.js'),
Expand Down
Loading

0 comments on commit f14e480

Please sign in to comment.