Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lucky-nails-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@preconstruct/cli": minor
---

Replace fs-extra with native node:fs/promises
2 changes: 1 addition & 1 deletion build/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
js-tokens "^4.0.0"
picocolors "^1.0.0"

"@babel/parser@^7.21.2", "@babel/parser@^7.24.7":
"@babel/parser@^7.24.7":
version "7.24.7"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.24.7.tgz#9a5226f92f0c5c8ead550b750f5608e766c8ce85"
integrity sha512-9uUYRm6OqQrCqQdG1iCBwBPZgN8ciDBro2nIOFaiRz1/BCxaI7CNvQbDHvsArAC7Tw9Hda/B3U+6ui9u4HWXPw==
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@
"@changesets/cli": "^2.27.1",
"@manypkg/cli": "^0.17.0",
"@types/babel__code-frame": "^7.0.1",
"@types/fs-extra": "^9.0.6",
"@types/jest": "^29.2.2",
"@types/ms": "^0.7.31",
"@types/node": "^18.11.9",
"@types/node": "^18.19.55",
"@types/normalize-path": "^3.0.0",
"@types/npm-packlist": "^1.1.1",
"@types/parse-glob": "^3.0.29",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
"estree-walker": "^2.0.1",
"fast-deep-equal": "^2.0.1",
"fast-glob": "^3.2.4",
"fs-extra": "^9.0.1",
"is-reference": "^1.2.1",
"jest-worker": "^26.3.0",
"magic-string": "^0.30.0",
Expand All @@ -81,6 +80,7 @@
},
"devDependencies": {
"@types/estree": "*",
"@types/node": "^18.19.55",
"escape-string-regexp": "^4.0.0",
"spawndamnit": "^2.0.0",
"strip-ansi": "^6.0.0"
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/__tests__/dev.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import spawn from "spawndamnit";
import path from "path";
import * as fs from "fs-extra";
import * as realFs from "fs";
import fs from "node:fs/promises";
import {
getFiles,
js,
Expand All @@ -10,6 +9,7 @@ import {
testdir,
ts,
typescriptFixture,
fsEnsureSymlink,
} from "../../test-utils";
import dev from "../dev";
import normalizePath from "normalize-path";
Expand Down Expand Up @@ -292,7 +292,7 @@ test("typescript", async () => {
});

test("exports field with worker condition", async () => {
let tmpPath = realFs.realpathSync.native(
let tmpPath = await fs.realpath(
await testdir({
"package.json": JSON.stringify({
name: "@something/blah",
Expand Down Expand Up @@ -471,7 +471,7 @@ test("with default", async () => {
},
}),
});
await fs.ensureSymlink(
await fsEnsureSymlink(
path.join(dir, "packages/pkg-a"),
path.join(dir, "node_modules/pkg-a")
);
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/__tests__/fix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
ts,
} from "../../test-utils";
import { promptInput as _promptInput } from "../prompt";
import fs from "fs-extra";
import fs from "node:fs/promises";

const f = fixturez(__dirname);

Expand Down
32 changes: 16 additions & 16 deletions packages/cli/src/build/__tests__/build.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import build from "../";
import fixturez from "fixturez";
import path from "path";
import fs from "fs-extra";
import {
initBasic,
getPkg,
Expand All @@ -15,6 +14,7 @@ import {
getFiles,
ts,
stripHashes,
fsEnsureSymlink,
} from "../../../test-utils";
import { doPromptInput as _doPromptInput } from "../../prompt";
import { confirms as _confirms } from "../../messages";
Expand Down Expand Up @@ -820,7 +820,7 @@ test("typescript with nodenext module resolution", async () => {
`,
...tsSetupFiles,
});
await fs.ensureSymlink(
await fsEnsureSymlink(
path.join(dir, "packages/pkg-a"),
path.join(dir, "node_modules/pkg-a")
);
Expand Down Expand Up @@ -1028,7 +1028,7 @@ test("correct default export using mjs and dmts proxies", async () => {
`,
...tsSetupFiles,
});
await fs.ensureSymlink(
await fsEnsureSymlink(
path.join(dir, "packages/pkg-a"),
path.join(dir, "node_modules/pkg-a")
);
Expand Down Expand Up @@ -1195,11 +1195,11 @@ test("importing a package via dynamic import from another package provides the r
`,
...tsSetupFiles,
});
await fs.ensureSymlink(
await fsEnsureSymlink(
path.join(dir, "packages/pkg-a"),
path.join(dir, "node_modules/pkg-a")
);
await fs.ensureSymlink(
await fsEnsureSymlink(
path.join(dir, "packages/pkg-b"),
path.join(dir, "node_modules/pkg-b")
);
Expand Down Expand Up @@ -1325,11 +1325,11 @@ test("importing another package via dynamic import and exporting the namespace p
`,
...tsSetupFiles,
});
await fs.ensureSymlink(
await fsEnsureSymlink(
path.join(dir, "packages/pkg-a"),
path.join(dir, "node_modules/pkg-a")
);
await fs.ensureSymlink(
await fsEnsureSymlink(
path.join(dir, "packages/pkg-b"),
path.join(dir, "node_modules/pkg-b")
);
Expand Down Expand Up @@ -1408,11 +1408,11 @@ test("importing another package via dynamic import and exporting something that
`,
...tsSetupFiles,
});
await fs.ensureSymlink(
await fsEnsureSymlink(
path.join(dir, "packages/pkg-a"),
path.join(dir, "node_modules/pkg-a")
);
await fs.ensureSymlink(
await fsEnsureSymlink(
path.join(dir, "packages/pkg-b"),
path.join(dir, "node_modules/pkg-b")
);
Expand Down Expand Up @@ -1516,7 +1516,7 @@ test("no __esModule when reexporting namespace with mjs proxy", async () => {
},
}),
});
await fs.ensureSymlink(
await fsEnsureSymlink(
path.join(dir, "packages/pkg-a"),
path.join(dir, "node_modules/pkg-a")
);
Expand Down Expand Up @@ -1652,7 +1652,7 @@ test("export * from external", async () => {
`,
...tsSetupFiles,
});
await fs.ensureSymlink(
await fsEnsureSymlink(
path.join(dir, "packages/pkg-a"),
path.join(dir, "node_modules/pkg-a")
);
Expand Down Expand Up @@ -1780,7 +1780,7 @@ test("type only export imported in .mts", async () => {
`,
...tsSetupFiles,
});
await fs.ensureSymlink(
await fsEnsureSymlink(
path.join(dir, "packages/pkg-a"),
path.join(dir, "node_modules/pkg-a")
);
Expand Down Expand Up @@ -2060,7 +2060,7 @@ test("correct default export using mjs and dmts proxies with moduleResolution: b
},
}),
});
await fs.ensureSymlink(
await fsEnsureSymlink(
path.join(dir, "packages/pkg-a"),
path.join(dir, "node_modules/pkg-a")
);
Expand Down Expand Up @@ -2203,7 +2203,7 @@ test("module with no runtime exports but with init-time side-effects with import
require("pkg-a");
`,
});
await fs.ensureSymlink(
await fsEnsureSymlink(
path.join(dir, "packages/pkg-a"),
path.join(dir, "node_modules/pkg-a")
);
Expand Down Expand Up @@ -2440,7 +2440,7 @@ test("using type from a package with .d.ts at entrypoint in another package", as
`,
...tsSetupFiles,
});
await fs.ensureSymlink(
await fsEnsureSymlink(
path.join(dir, "packages/pkg-a"),
path.join(dir, "node_modules/pkg-a")
);
Expand Down Expand Up @@ -2525,7 +2525,7 @@ test("using type from a package with .d.ts at entrypoint in another package with
`,
...tsSetupFiles,
});
await fs.ensureSymlink(
await fsEnsureSymlink(
path.join(dir, "packages/pkg-a"),
path.join(dir, "node_modules/pkg-a")
);
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Project } from "../project";
import path from "path";
import { rollup, OutputAsset, OutputChunk, OutputOptions } from "rollup";
import * as logger from "../logger";
import * as fs from "fs-extra";
import {
FatalError,
UnexpectedBuildError,
Expand All @@ -14,6 +13,7 @@ import { getRollupConfigs } from "./config";
import { createWorker, destroyWorker } from "../worker-client";
import { validateProject } from "../validate";
import { cleanProjectBeforeBuild } from "./utils";
import { fsOutputFile } from "../utils";

// https://github.com/rollup/rollup/blob/28ffcf4c4a2ab4323091f63944b2a609b7bcd701/src/utils/sourceMappingURL.ts
// this looks ridiculous, but it prevents sourcemap tooling from mistaking
Expand Down Expand Up @@ -42,7 +42,7 @@ function writeOutputFile(
url = outputFile.map.toUrl();
} else {
url = `${path.basename(outputFile.fileName)}.map`;
writeSourceMapPromise = fs.outputFile(
writeSourceMapPromise = fsOutputFile(
`${fileName}.map`,
outputFile.map.toString()
);
Expand All @@ -53,7 +53,7 @@ function writeOutputFile(
}
}

return Promise.all([fs.outputFile(fileName, source), writeSourceMapPromise]);
return Promise.all([fsOutputFile(fileName, source), writeSourceMapPromise]);
}

async function buildPackage(pkg: Package) {
Expand Down
14 changes: 10 additions & 4 deletions packages/cli/src/build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
hasDtsFile,
writeDevTSFiles,
} from "../dev";
import * as fs from "fs-extra";
import fs from "node:fs/promises";
import path from "path";

export function getDevPath(cjsPath: string) {
Expand All @@ -20,11 +20,17 @@ export async function cleanProjectBeforeBuild(project: Project) {
await Promise.all(
project.packages.map(async (pkg) => {
await Promise.all([
fs.remove(path.join(pkg.directory, "dist")),
fs.rm(path.join(pkg.directory, "dist"), {
recursive: true,
force: true,
}),
...pkg.entrypoints
.filter((entrypoint) => entrypoint.name !== pkg.name)
.map((entrypoint) => {
return fs.remove(path.join(entrypoint.directory, "dist"));
.map(async (entrypoint) => {
await fs.rm(path.join(entrypoint.directory, "dist"), {
recursive: true,
force: true,
});
}),
]);
const isTypeModule = pkg.isTypeModule();
Expand Down
17 changes: 9 additions & 8 deletions packages/cli/src/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import {
getDistFilenameForConditions,
getBaseDistName,
getDistFilenameForConditionsWithTypeModule,
fsOutputFile,
} from "./utils";
import * as fs from "fs-extra";
import fs from "node:fs/promises";
import path from "path";
import normalizePath from "normalize-path";
import { Entrypoint } from "./entrypoint";
Expand Down Expand Up @@ -109,7 +110,7 @@ export async function writeDevTSFiles(
const pathToImport = replaceTsExtensionWithJs(relativePathWithExtension);

let promises: Promise<unknown>[] = [
fs.outputFile(
fsOutputFile(
dtsReexportFilename,
dtsTemplate(
baseDtsFilename,
Expand All @@ -131,7 +132,7 @@ export async function writeDevTSFiles(
const baseDmtsFilename = path.basename(dmtsReexportFilename);

promises.push(
fs.outputFile(
fsOutputFile(
dmtsReexportFilename,
dmtsTemplate(
baseDmtsFilename,
Expand All @@ -143,7 +144,7 @@ export async function writeDevTSFiles(
);
if (hasDefaultExport) {
promises.push(
fs.outputFile(
fsOutputFile(
getDtsDefaultForMtsFilepath(dmtsReexportFilename),
dtsDefaultForDmtsTemplate(pathToImport)
)
Expand Down Expand Up @@ -189,8 +190,8 @@ export default async function dev(projectDir: string) {
project.packages.map(async (pkg) => {
const exportsFieldConfig = pkg.exportsFieldConfig();
let distDirectory = path.join(pkg.directory, "dist");
await fs.remove(distDirectory);
await fs.ensureDir(distDirectory);
await fs.rm(distDirectory, { recursive: true, force: true });
await fs.mkdir(distDirectory, { recursive: true });

return Promise.all(
pkg.entrypoints.map(async (entrypoint) => {
Expand Down Expand Up @@ -406,9 +407,9 @@ async function cleanEntrypoint(entrypoint: Entrypoint) {
if (entrypoint.package.name === entrypoint.name) return;
let distDirectory = path.join(entrypoint.directory, "dist");

await fs.remove(distDirectory);
await fs.rm(distDirectory, { recursive: true, force: true });
if (!entrypoint.package.project.experimentalFlags.distInRoot) {
await fs.ensureDir(distDirectory);
await fs.mkdir(distDirectory, { recursive: true });
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/glob-thing.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import parseGlob from "parse-glob";
import * as fs from "fs-extra";
import fs from "node:fs/promises";
import path from "path";
import normalizePath from "normalize-path";

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/item.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as fs from "fs-extra";
import fs from "node:fs/promises";
import nodePath from "path";
import detectIndent from "detect-indent";
import parseJson from "parse-json";
Expand Down
Loading