fix: switch to nodeModulesDir: "manual" (#3588)

The `"auto"` value causes all kinds of race conditions between various
processes trying to auto install their view of dependencies.
This commit is contained in:
Marvin Hagemeister
2025-10-30 14:50:49 +01:00
committed by GitHub
parent 45bb094bd6
commit 5e94dfe9fd
6 changed files with 129 additions and 28 deletions
Generated
+24 -2
View File
@@ -41,6 +41,7 @@
"jsr:@std/html@1": "1.0.5",
"jsr:@std/html@^1.0.5": "1.0.5",
"jsr:@std/http@^1.0.15": "1.0.21",
"jsr:@std/http@^1.0.21": "1.0.21",
"jsr:@std/internal@^1.0.10": "1.0.12",
"jsr:@std/internal@^1.0.12": "1.0.12",
"jsr:@std/internal@^1.0.9": "1.0.12",
@@ -48,6 +49,7 @@
"jsr:@std/io@0.225.0": "0.225.0",
"jsr:@std/json@^1.0.2": "1.0.2",
"jsr:@std/jsonc@1": "1.0.2",
"jsr:@std/jsonc@^1.0.2": "1.0.2",
"jsr:@std/media-types@1": "1.1.0",
"jsr:@std/media-types@^1.1.0": "1.1.0",
"jsr:@std/net@^1.0.6": "1.0.6",
@@ -55,12 +57,14 @@
"jsr:@std/path@^1.0.8": "1.1.2",
"jsr:@std/path@^1.1.1": "1.1.2",
"jsr:@std/path@^1.1.2": "1.1.2",
"jsr:@std/semver@1": "1.0.5",
"jsr:@std/semver@1": "1.0.6",
"jsr:@std/semver@^1.0.6": "1.0.6",
"jsr:@std/streams@1": "1.0.13",
"jsr:@std/streams@^1.0.13": "1.0.13",
"jsr:@std/testing@^1.0.12": "1.0.16",
"jsr:@std/toml@^1.0.3": "1.0.10",
"jsr:@std/uuid@^1.0.7": "1.0.9",
"jsr:@std/uuid@^1.0.9": "1.0.9",
"jsr:@std/yaml@^1.0.5": "1.0.9",
"jsr:@zip-js/zip-js@^2.7.52": "2.8.8",
"npm:@babel/core@^7.28.0": "7.28.5",
@@ -98,9 +102,11 @@
"npm:postcss@8.5.6": "8.5.6",
"npm:postcss@^8.5.6": "8.5.6",
"npm:preact-render-to-string@^6.5.11": "6.6.3_preact@10.27.2",
"npm:preact-render-to-string@^6.6.3": "6.6.3_preact@10.27.2",
"npm:preact@^10.22.0": "10.27.2",
"npm:preact@^10.26.9": "10.27.2",
"npm:preact@^10.27.0": "10.27.2",
"npm:preact@^10.27.2": "10.27.2",
"npm:prismjs@^1.29.0": "1.30.0",
"npm:qs@^6.14.0": "6.14.0",
"npm:redis@^5.8.2": "5.9.0_@redis+client@5.9.0",
@@ -301,6 +307,9 @@
"@std/semver@1.0.5": {
"integrity": "529f79e83705714c105ad0ba55bec0f9da0f24d2f726b6cc1c15e505cc2c0624"
},
"@std/semver@1.0.6": {
"integrity": "b7c98ae2843547cf3f7ac37f3995889e6e4cee0a97b57b57f17f62722843303c"
},
"@std/streams@1.0.13": {
"integrity": "772d208cd0d3e5dac7c1d9e6cdb25842846d136eea4a41a62e44ed4ab0c8dd9e",
"dependencies": [
@@ -3852,8 +3861,21 @@
},
"packages/fresh": {
"dependencies": [
"jsr:@deno/esbuild-plugin@^1.2.0",
"jsr:@std/encoding@^1.0.10",
"jsr:@std/fmt@^1.0.8",
"npm:@types/node@^24.2.1"
"jsr:@std/fs@^1.0.19",
"jsr:@std/html@^1.0.5",
"jsr:@std/http@^1.0.21",
"jsr:@std/jsonc@^1.0.2",
"jsr:@std/media-types@^1.1.0",
"jsr:@std/path@^1.1.2",
"jsr:@std/semver@^1.0.6",
"jsr:@std/uuid@^1.0.9",
"npm:@opentelemetry/api@^1.9.0",
"npm:@types/node@^24.2.1",
"npm:preact-render-to-string@^6.6.3",
"npm:preact@^10.27.2"
]
},
"packages/plugin-tailwindcss-v3": {
+4 -4
View File
@@ -75,12 +75,12 @@ export default {
5. Update your `deno.json` file and add the following `tailwindcss` imports. To
make the
[vscode Tailwind CSS extension](https://marketplace.visualstudio.com/items?itemName=bradlc.vscode-tailwindcss)
work, we also need to set `"nodeModulesDir": "auto"`. This will create a
`node_modules` directory in your project folder:
work, we also need to set `"nodeModulesDir": "manual"`. This will create a
`node_modules` directory in your project folder when you run `deno install`.
```diff deno.json
{
+ "nodeModulesDir": "auto",
+ "nodeModulesDir": "manual",
"imports": {
"$fresh/": "https://deno.land/x/fresh@1.5.2/",
"preact": "https://esm.sh/preact@10.22.0",
@@ -104,7 +104,7 @@ That's it! Now you can use Tailwind CSS in your project.
> [info]: If you're a vscode user, be sure to install the
> [official Tailwind CSS extension](https://marketplace.visualstudio.com/items?itemName=bradlc.vscode-tailwindcss)
> to get full intellisense support. For it to work you also need to set
> `"nodeModulesDir": "auto"` in your `deno.json`.
> `"nodeModulesDir": "manual"` in your `deno.json`.
> [warn]: Tailwind CSS doesn't support the grouping syntax from twind:
> `text(lg uppercase gray-100)`. These need to be rewritten to their expanded
+2 -2
View File
@@ -138,12 +138,12 @@ that.
### Usage
1. Set `nodeModulesDir` in `deno.json` to `"auto"` or `"manual"`
1. Set `nodeModulesDir` in `deno.json` to `"manual"`
```diff deno.json
{
"name": "@example/my-cool-project"
+ "nodeModulesDir": "auto",
+ "nodeModulesDir": "manual",
"imports": {
...
}
+14 -1
View File
@@ -12,7 +12,20 @@
"./internal-dev": "./src/internals_dev.ts"
},
"imports": {
"@deno/esbuild-plugin": "jsr:@deno/esbuild-plugin@^1.2.0",
"@opentelemetry/api": "npm:@opentelemetry/api@^1.9.0",
"@std/encoding": "jsr:@std/encoding@^1.0.10",
"@std/fmt": "jsr:@std/fmt@^1.0.8",
"@types/node": "npm:@types/node@^24.2.1"
"@std/fs": "jsr:@std/fs@^1.0.19",
"@std/html": "jsr:@std/html@^1.0.5",
"@std/http": "jsr:@std/http@^1.0.21",
"@std/jsonc": "jsr:@std/jsonc@^1.0.2",
"@std/media-types": "jsr:@std/media-types@^1.1.0",
"@std/path": "jsr:@std/path@^1.1.2",
"@std/semver": "jsr:@std/semver@^1.0.6",
"@std/uuid": "jsr:@std/uuid@^1.0.9",
"@types/node": "npm:@types/node@^24.2.1",
"preact": "npm:preact@^10.27.2",
"preact-render-to-string": "npm:preact-render-to-string@^6.6.3"
}
}
+11 -1
View File
@@ -86,6 +86,7 @@ export async function initProject(
builder?: boolean | null;
help?: boolean | null;
h?: boolean | null;
skipInstall?: boolean | null;
} = {},
): Promise<void> {
const freshVersion = await getLatestVersion("@fresh/core", FRESH_VERSION);
@@ -559,7 +560,7 @@ if (Deno.args.includes("build")) {
}
const denoJson = {
nodeModulesDir: "auto",
nodeModulesDir: "manual",
tasks: {
check: "deno fmt --check . && deno lint . && deno check",
dev: "deno run -A --watch=static/,routes/ dev.ts",
@@ -763,6 +764,15 @@ This will watch the project directory and restart as necessary.`;
}
}
if (!flags.skipInstall) {
console.log("Installing dependencies...");
await new Deno.Command(Deno.execPath(), {
cwd: unresolvedDirectory,
args: ["install"],
}).output();
console.log("Installing dependencies...%cdone!", "color: green");
}
// Specifically print unresolvedDirectory, rather than resolvedDirectory in order to
// not leak personal info (e.g. `/Users/MyName`)
console.log(
+74 -18
View File
@@ -16,6 +16,10 @@ import { stub } from "@std/testing/mock";
// deno-lint-ignore no-explicit-any
(globalThis as any).INIT_TEST = true;
const testInitProject: typeof initProject = async (cwd, input, flags = {}) => {
return await initProject(cwd, input, { ...flags, skipInstall: true });
};
function stubPrompt(result: string) {
return stub(globalThis, "prompt", () => result);
}
@@ -49,15 +53,67 @@ async function patchProject(dir: string): Promise<void> {
const jsonPath = path.join(dir, "deno.json");
const json = JSON.parse(await Deno.readTextFile(jsonPath));
json.workspace = [];
// See https://github.com/denoland/deno/issues/27313
// json.links = [path.fromFileURL(new URL("../..", import.meta.url))];
json.links = [new URL("../../fresh", import.meta.url).href];
const linkedDir = path.join(dir, "_linked");
try {
await Deno.mkdir(linkedDir, { recursive: true });
} catch (err) {
if (!(err instanceof Deno.errors.AlreadyExists)) {
throw err;
}
}
const ignore = /[/\\]+(.|[^/\\]+_test\..*|tests[^/\\])/;
await copyRecursive(
path.join(import.meta.dirname!, "..", "..", "fresh"),
path.join(linkedDir, "fresh"),
ignore,
);
await copyRecursive(
path.join(import.meta.dirname!, "..", "..", "build-id"),
path.join(linkedDir, "build-id"),
ignore,
);
json.workspace = ["./_linked/*"];
// assert with this stricter rule, before adding it to initialized projects
json.lint.rules.include = ["verbatim-module-syntax"];
await Deno.writeTextFile(jsonPath, JSON.stringify(json, null, 2) + "\n");
const { code } = await new Deno.Command(Deno.execPath(), {
cwd: dir,
args: ["install"],
}).output();
expect(code).toEqual(0);
}
async function copyRecursive(
from: string,
to: string,
ignore?: RegExp,
): Promise<void> {
for await (const entry of Deno.readDir(from)) {
const source = path.join(from, entry.name);
const target = path.join(to, entry.name);
if (ignore && ignore.test(source)) continue;
if (entry.isFile) {
try {
await Deno.mkdir(to, { recursive: true });
} catch (err) {
if (!(err instanceof Deno.errors.AlreadyExists)) {
throw err;
}
}
await Deno.copyFile(source, target);
} else if (entry.isDirectory) {
await copyRecursive(source, target);
}
}
}
async function expectProjectFile(dir: string, pathname: string) {
@@ -91,10 +147,10 @@ async function readProjectFile(dir: string, pathname: string): Promise<string> {
Deno.test("init - show help", async () => {
using logs = stubLogs();
await initProject("", [], { help: true });
await testInitProject("", [], { help: true });
const args = logs.calls.flatMap((c) => c.args);
const out = args.join("\n");
await initProject("", [], { h: true });
await testInitProject("", [], { h: true });
expect(out).toBe(HELP_TEXT);
expect(args).toEqual(logs.calls.flatMap((c) => c.args).slice(args.length));
@@ -105,7 +161,7 @@ Deno.test("init - new project", async () => {
using _promptStub = stubPrompt("fresh-init");
using _confirmStub = stubConfirm();
await initProject(tmp.dir, [], { builder: true });
await testInitProject(tmp.dir, [], { builder: true });
});
Deno.test("init - create project dir", async () => {
@@ -113,7 +169,7 @@ Deno.test("init - create project dir", async () => {
const dir = tmp.dir;
using _promptStub = stubPrompt("fresh-init");
using _confirmStub = stubConfirm();
await initProject(dir, [], { builder: true });
await testInitProject(dir, [], { builder: true });
const root = path.join(dir, "fresh-init");
await expectProjectFile(root, "deno.json");
@@ -130,7 +186,7 @@ Deno.test("init - with tailwind", async () => {
using _confirmStub = stubConfirm({
[CONFIRM_TAILWIND_MESSAGE]: true,
});
await initProject(dir, [], { builder: true });
await testInitProject(dir, [], { builder: true });
const css = await readProjectFile(dir, "static/styles.css");
expect(css).toMatch(/@import "tailwindcss"/);
@@ -148,7 +204,7 @@ Deno.test("init - with vscode", async () => {
using _confirmStub = stubConfirm({
[CONFIRM_VSCODE_MESSAGE]: true,
});
await initProject(dir, [], { builder: true });
await testInitProject(dir, [], { builder: true });
await expectProjectFile(dir, ".vscode/settings.json");
await expectProjectFile(dir, ".vscode/extensions.json");
@@ -164,7 +220,7 @@ Deno.test({
const dir = tmp.dir;
using _promptStub = stubPrompt(".");
using _confirmStub = stubConfirm();
await initProject(dir, [], { builder: true });
await testInitProject(dir, [], { builder: true });
await expectProjectFile(dir, "main.ts");
await expectProjectFile(dir, "dev.ts");
@@ -190,7 +246,7 @@ Deno.test(
[CONFIRM_TAILWIND_MESSAGE]: true,
});
await initProject(dir, [], { builder: true });
await testInitProject(dir, [], { builder: true });
await expectProjectFile(dir, "main.ts");
await expectProjectFile(dir, "dev.ts");
@@ -216,7 +272,7 @@ Deno.test({
const dir = tmp.dir;
using _promptStub = stubPrompt(".");
using _confirmStub = stubConfirm();
await initProject(dir, [], { builder: true });
await testInitProject(dir, [], { builder: true });
await expectProjectFile(dir, "main.ts");
await expectProjectFile(dir, "dev.ts");
@@ -239,7 +295,7 @@ Deno.test("init - can start built project", async () => {
const dir = tmp.dir;
using _promptStub = stubPrompt(".");
using _confirmStub = stubConfirm();
await initProject(dir, [], { builder: true });
await testInitProject(dir, [], { builder: true });
await expectProjectFile(dir, "main.ts");
await expectProjectFile(dir, "dev.ts");
@@ -271,7 +327,7 @@ Deno.test("init - errors on missing build cache in prod", async () => {
const dir = tmp.dir;
using _promptStub = stubPrompt(".");
using _confirmStub = stubConfirm();
await initProject(dir, [], { builder: true });
await testInitProject(dir, [], { builder: true });
await expectProjectFile(dir, "main.ts");
await expectProjectFile(dir, "dev.ts");
@@ -297,7 +353,7 @@ Deno.test.ignore("init - vite dev server", async () => {
const dir = tmp.dir;
using _promptStub = stubPrompt(".");
using _confirmStub = stubConfirm();
await initProject(dir, [], {});
await testInitProject(dir, [], {});
await expectProjectFile(dir, "vite.config.ts");
await expectNotProjectFile(dir, "dev.ts");
@@ -322,7 +378,7 @@ Deno.test.ignore("init - vite build", async () => {
const dir = tmp.dir;
using _promptStub = stubPrompt(".");
using _confirmStub = stubConfirm();
await initProject(dir, [], {});
await testInitProject(dir, [], {});
await expectProjectFile(dir, "vite.config.ts");
@@ -356,7 +412,7 @@ Deno.test("init - with vite", async () => {
using _confirmStub = stubConfirm({
[CONFIRM_VITE_MESSAGE]: true,
});
await initProject(dir, [], {});
await testInitProject(dir, [], {});
await expectProjectFile(dir, "vite.config.ts");
await expectNotProjectFile(dir, "dev.ts");