@multiplatform.one/utils 6.6.0 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/dev.cjs +45 -3
- package/lib/dev.mjs +44 -3
- package/package.json +2 -2
- package/src/dev.ts +63 -3
- package/types/dev.d.ts +8 -0
- package/types/dev.d.ts.map +1 -1
package/lib/dev.cjs
CHANGED
|
@@ -30,6 +30,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
let node_child_process = require("node:child_process");
|
|
31
31
|
let node_fs = require("node:fs");
|
|
32
32
|
node_fs = __toESM(node_fs, 1);
|
|
33
|
+
let node_module = require("node:module");
|
|
33
34
|
let node_path = require("node:path");
|
|
34
35
|
node_path = __toESM(node_path, 1);
|
|
35
36
|
let axios = require("axios");
|
|
@@ -22674,21 +22675,62 @@ function workspaceSourceAliases(workspaceRoot) {
|
|
|
22674
22675
|
return sorted;
|
|
22675
22676
|
}
|
|
22676
22677
|
/**
|
|
22678
|
+
* Locate the installed `one` package directory without assuming the npm/yarn
|
|
22679
|
+
* hoisted layout (`<root>/node_modules/one`). Under pnpm's default isolated
|
|
22680
|
+
* layout `one` lives in the importing package's own node_modules (e.g.
|
|
22681
|
+
* `apps/<app>/node_modules/one`), so resolve like node would from the build
|
|
22682
|
+
* cwd and the workspace root, fall back to this package's own resolution
|
|
22683
|
+
* (covers pnpm's `.pnpm/node_modules` fallback), then scan upward for a
|
|
22684
|
+
* physical `node_modules/one`.
|
|
22685
|
+
*/
|
|
22686
|
+
function resolveOnePackageDir(root) {
|
|
22687
|
+
for (const base of [node_path.default.join(process.cwd(), "package.json"), node_path.default.join(root, "package.json")]) try {
|
|
22688
|
+
return node_path.default.dirname((0, node_module.createRequire)(base).resolve("one/package.json"));
|
|
22689
|
+
} catch {}
|
|
22690
|
+
try {
|
|
22691
|
+
return node_path.default.dirname((0, node_module.createRequire)(require("url").pathToFileURL(__filename).href).resolve("one/package.json"));
|
|
22692
|
+
} catch {}
|
|
22693
|
+
let dir = root;
|
|
22694
|
+
while (true) {
|
|
22695
|
+
const candidate = node_path.default.join(dir, "node_modules/one");
|
|
22696
|
+
if (node_fs.default.existsSync(node_path.default.join(candidate, "package.json"))) return candidate;
|
|
22697
|
+
const parent = node_path.default.dirname(dir);
|
|
22698
|
+
if (parent === dir) return void 0;
|
|
22699
|
+
dir = parent;
|
|
22700
|
+
}
|
|
22701
|
+
}
|
|
22702
|
+
/**
|
|
22677
22703
|
* one's client code imports ./vite/one-server-only.mjs, which pulls
|
|
22678
22704
|
* node:async_hooks and can't bundle for the browser. Declaring it rollup-
|
|
22679
22705
|
* `external` ships a literal node_modules import that can't resolve inside a
|
|
22680
22706
|
* packaged extension (this exact failure made the webext popup load blank).
|
|
22681
22707
|
* One publishes a no-op browser/native variant of the same module; redirect
|
|
22682
22708
|
* to it instead of externalizing.
|
|
22709
|
+
*
|
|
22710
|
+
* When `one` is not installed at all, the redirect is skipped (with a one-line
|
|
22711
|
+
* warning) so normal resolution proceeds instead of rewriting matching ids to
|
|
22712
|
+
* a path that does not exist — which surfaced as a bare "No such file or
|
|
22713
|
+
* directory" naming the consumer's own import. The redirect also only applies
|
|
22714
|
+
* to imports made FROM one's own files (every real one-server-only import
|
|
22715
|
+
* site lives in one/dist); a consumer module whose id merely contains the
|
|
22716
|
+
* substring resolves normally.
|
|
22683
22717
|
*/
|
|
22684
22718
|
function oneServerOnlyBrowserStub(workspaceRoot) {
|
|
22685
22719
|
const root = workspaceRoot ?? lookupProjectRoot();
|
|
22686
|
-
const
|
|
22720
|
+
const oneDir = resolveOnePackageDir(root);
|
|
22721
|
+
if (!oneDir) {
|
|
22722
|
+
logger.warn(`[one-server-only-browser-stub] cannot resolve the "one" package from ${root} — skipping the one-server-only browser redirect (normal resolution proceeds)`);
|
|
22723
|
+
return { name: "one-server-only-browser-stub" };
|
|
22724
|
+
}
|
|
22725
|
+
const stub = node_path.default.join(oneDir, "dist/esm/vite/one-server-only.native.js");
|
|
22687
22726
|
return {
|
|
22688
22727
|
name: "one-server-only-browser-stub",
|
|
22689
22728
|
enforce: "pre",
|
|
22690
|
-
resolveId(id) {
|
|
22691
|
-
if (id.includes("one-server-only")) return
|
|
22729
|
+
resolveId(id, importer) {
|
|
22730
|
+
if (!id.includes("one-server-only")) return;
|
|
22731
|
+
if (!importer || !(importer.includes("/node_modules/one/") || importer.startsWith(`${oneDir}/`))) return;
|
|
22732
|
+
if (!node_fs.default.existsSync(stub)) throw new Error(`[one-server-only-browser-stub] "${id}" matched the one-server-only browser redirect, but the stub target does not exist: ${stub}. The installed "one" package has an unexpected layout — reinstall one, or pass a workspaceRoot whose node_modules contains one/dist/esm/vite/one-server-only.native.js.`);
|
|
22733
|
+
return stub;
|
|
22692
22734
|
}
|
|
22693
22735
|
};
|
|
22694
22736
|
}
|
package/lib/dev.mjs
CHANGED
|
@@ -22647,21 +22647,62 @@ function workspaceSourceAliases(workspaceRoot) {
|
|
|
22647
22647
|
return sorted;
|
|
22648
22648
|
}
|
|
22649
22649
|
/**
|
|
22650
|
+
* Locate the installed `one` package directory without assuming the npm/yarn
|
|
22651
|
+
* hoisted layout (`<root>/node_modules/one`). Under pnpm's default isolated
|
|
22652
|
+
* layout `one` lives in the importing package's own node_modules (e.g.
|
|
22653
|
+
* `apps/<app>/node_modules/one`), so resolve like node would from the build
|
|
22654
|
+
* cwd and the workspace root, fall back to this package's own resolution
|
|
22655
|
+
* (covers pnpm's `.pnpm/node_modules` fallback), then scan upward for a
|
|
22656
|
+
* physical `node_modules/one`.
|
|
22657
|
+
*/
|
|
22658
|
+
function resolveOnePackageDir(root) {
|
|
22659
|
+
for (const base of [path.join(process.cwd(), "package.json"), path.join(root, "package.json")]) try {
|
|
22660
|
+
return path.dirname(createRequire(base).resolve("one/package.json"));
|
|
22661
|
+
} catch {}
|
|
22662
|
+
try {
|
|
22663
|
+
return path.dirname(createRequire(import.meta.url).resolve("one/package.json"));
|
|
22664
|
+
} catch {}
|
|
22665
|
+
let dir = root;
|
|
22666
|
+
while (true) {
|
|
22667
|
+
const candidate = path.join(dir, "node_modules/one");
|
|
22668
|
+
if (fs.existsSync(path.join(candidate, "package.json"))) return candidate;
|
|
22669
|
+
const parent = path.dirname(dir);
|
|
22670
|
+
if (parent === dir) return void 0;
|
|
22671
|
+
dir = parent;
|
|
22672
|
+
}
|
|
22673
|
+
}
|
|
22674
|
+
/**
|
|
22650
22675
|
* one's client code imports ./vite/one-server-only.mjs, which pulls
|
|
22651
22676
|
* node:async_hooks and can't bundle for the browser. Declaring it rollup-
|
|
22652
22677
|
* `external` ships a literal node_modules import that can't resolve inside a
|
|
22653
22678
|
* packaged extension (this exact failure made the webext popup load blank).
|
|
22654
22679
|
* One publishes a no-op browser/native variant of the same module; redirect
|
|
22655
22680
|
* to it instead of externalizing.
|
|
22681
|
+
*
|
|
22682
|
+
* When `one` is not installed at all, the redirect is skipped (with a one-line
|
|
22683
|
+
* warning) so normal resolution proceeds instead of rewriting matching ids to
|
|
22684
|
+
* a path that does not exist — which surfaced as a bare "No such file or
|
|
22685
|
+
* directory" naming the consumer's own import. The redirect also only applies
|
|
22686
|
+
* to imports made FROM one's own files (every real one-server-only import
|
|
22687
|
+
* site lives in one/dist); a consumer module whose id merely contains the
|
|
22688
|
+
* substring resolves normally.
|
|
22656
22689
|
*/
|
|
22657
22690
|
function oneServerOnlyBrowserStub(workspaceRoot) {
|
|
22658
22691
|
const root = workspaceRoot ?? lookupProjectRoot();
|
|
22659
|
-
const
|
|
22692
|
+
const oneDir = resolveOnePackageDir(root);
|
|
22693
|
+
if (!oneDir) {
|
|
22694
|
+
logger.warn(`[one-server-only-browser-stub] cannot resolve the "one" package from ${root} — skipping the one-server-only browser redirect (normal resolution proceeds)`);
|
|
22695
|
+
return { name: "one-server-only-browser-stub" };
|
|
22696
|
+
}
|
|
22697
|
+
const stub = path.join(oneDir, "dist/esm/vite/one-server-only.native.js");
|
|
22660
22698
|
return {
|
|
22661
22699
|
name: "one-server-only-browser-stub",
|
|
22662
22700
|
enforce: "pre",
|
|
22663
|
-
resolveId(id) {
|
|
22664
|
-
if (id.includes("one-server-only")) return
|
|
22701
|
+
resolveId(id, importer) {
|
|
22702
|
+
if (!id.includes("one-server-only")) return;
|
|
22703
|
+
if (!importer || !(importer.includes("/node_modules/one/") || importer.startsWith(`${oneDir}/`))) return;
|
|
22704
|
+
if (!fs.existsSync(stub)) throw new Error(`[one-server-only-browser-stub] "${id}" matched the one-server-only browser redirect, but the stub target does not exist: ${stub}. The installed "one" package has an unexpected layout — reinstall one, or pass a workspaceRoot whose node_modules contains one/dist/esm/vite/one-server-only.native.js.`);
|
|
22705
|
+
return stub;
|
|
22665
22706
|
}
|
|
22666
22707
|
};
|
|
22667
22708
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@multiplatform.one/utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "utilities for multiplatform.one",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"multiplatform.one",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"node": ">=6.0.0"
|
|
66
66
|
},
|
|
67
67
|
"scripts": {
|
|
68
|
-
"typecheck": "
|
|
68
|
+
"typecheck": "tsgo --noEmit",
|
|
69
69
|
"build": "rm -rf lib types 2>/dev/null && tsc -p tsconfig.build.json && tsdown",
|
|
70
70
|
"test": "vitest run --coverage --coverage.provider=v8 --coverage.reporter=text --coverage.reporter=lcov --coverage.reporter=html"
|
|
71
71
|
}
|
package/src/dev.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
2
|
import fs from "node:fs";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
import type { Plugin } from "vite";
|
|
5
6
|
|
|
@@ -155,6 +156,34 @@ export function workspaceSourceAliases(workspaceRoot?: string): Record<string, s
|
|
|
155
156
|
return sorted;
|
|
156
157
|
}
|
|
157
158
|
|
|
159
|
+
/**
|
|
160
|
+
* Locate the installed `one` package directory without assuming the npm/yarn
|
|
161
|
+
* hoisted layout (`<root>/node_modules/one`). Under pnpm's default isolated
|
|
162
|
+
* layout `one` lives in the importing package's own node_modules (e.g.
|
|
163
|
+
* `apps/<app>/node_modules/one`), so resolve like node would from the build
|
|
164
|
+
* cwd and the workspace root, fall back to this package's own resolution
|
|
165
|
+
* (covers pnpm's `.pnpm/node_modules` fallback), then scan upward for a
|
|
166
|
+
* physical `node_modules/one`.
|
|
167
|
+
*/
|
|
168
|
+
function resolveOnePackageDir(root: string): string | undefined {
|
|
169
|
+
for (const base of [path.join(process.cwd(), "package.json"), path.join(root, "package.json")]) {
|
|
170
|
+
try {
|
|
171
|
+
return path.dirname(createRequire(base).resolve("one/package.json"));
|
|
172
|
+
} catch {}
|
|
173
|
+
}
|
|
174
|
+
try {
|
|
175
|
+
return path.dirname(createRequire(import.meta.url).resolve("one/package.json"));
|
|
176
|
+
} catch {}
|
|
177
|
+
let dir = root;
|
|
178
|
+
while (true) {
|
|
179
|
+
const candidate = path.join(dir, "node_modules/one");
|
|
180
|
+
if (fs.existsSync(path.join(candidate, "package.json"))) return candidate;
|
|
181
|
+
const parent = path.dirname(dir);
|
|
182
|
+
if (parent === dir) return undefined;
|
|
183
|
+
dir = parent;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
158
187
|
/**
|
|
159
188
|
* one's client code imports ./vite/one-server-only.mjs, which pulls
|
|
160
189
|
* node:async_hooks and can't bundle for the browser. Declaring it rollup-
|
|
@@ -162,15 +191,46 @@ export function workspaceSourceAliases(workspaceRoot?: string): Record<string, s
|
|
|
162
191
|
* packaged extension (this exact failure made the webext popup load blank).
|
|
163
192
|
* One publishes a no-op browser/native variant of the same module; redirect
|
|
164
193
|
* to it instead of externalizing.
|
|
194
|
+
*
|
|
195
|
+
* When `one` is not installed at all, the redirect is skipped (with a one-line
|
|
196
|
+
* warning) so normal resolution proceeds instead of rewriting matching ids to
|
|
197
|
+
* a path that does not exist — which surfaced as a bare "No such file or
|
|
198
|
+
* directory" naming the consumer's own import. The redirect also only applies
|
|
199
|
+
* to imports made FROM one's own files (every real one-server-only import
|
|
200
|
+
* site lives in one/dist); a consumer module whose id merely contains the
|
|
201
|
+
* substring resolves normally.
|
|
165
202
|
*/
|
|
166
203
|
export function oneServerOnlyBrowserStub(workspaceRoot?: string): Plugin {
|
|
167
204
|
const root = workspaceRoot ?? lookupProjectRoot();
|
|
168
|
-
const
|
|
205
|
+
const oneDir = resolveOnePackageDir(root);
|
|
206
|
+
if (!oneDir) {
|
|
207
|
+
logger.warn(
|
|
208
|
+
`[one-server-only-browser-stub] cannot resolve the "one" package from ${root} — ` +
|
|
209
|
+
"skipping the one-server-only browser redirect (normal resolution proceeds)",
|
|
210
|
+
);
|
|
211
|
+
return { name: "one-server-only-browser-stub" };
|
|
212
|
+
}
|
|
213
|
+
const stub = path.join(oneDir, "dist/esm/vite/one-server-only.native.js");
|
|
169
214
|
return {
|
|
170
215
|
name: "one-server-only-browser-stub",
|
|
171
216
|
enforce: "pre",
|
|
172
|
-
resolveId(id: string) {
|
|
173
|
-
if (id.includes("one-server-only")) return
|
|
217
|
+
resolveId(id: string, importer?: string) {
|
|
218
|
+
if (!id.includes("one-server-only")) return;
|
|
219
|
+
if (
|
|
220
|
+
!importer ||
|
|
221
|
+
!(importer.includes("/node_modules/one/") || importer.startsWith(`${oneDir}/`))
|
|
222
|
+
) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
if (!fs.existsSync(stub)) {
|
|
226
|
+
throw new Error(
|
|
227
|
+
`[one-server-only-browser-stub] "${id}" matched the one-server-only browser ` +
|
|
228
|
+
`redirect, but the stub target does not exist: ${stub}. The installed "one" ` +
|
|
229
|
+
"package has an unexpected layout — reinstall one, or pass a workspaceRoot " +
|
|
230
|
+
"whose node_modules contains one/dist/esm/vite/one-server-only.native.js.",
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
return stub;
|
|
174
234
|
},
|
|
175
235
|
};
|
|
176
236
|
}
|
package/types/dev.d.ts
CHANGED
|
@@ -25,6 +25,14 @@ export declare function workspaceSourceAliases(workspaceRoot?: string): Record<s
|
|
|
25
25
|
* packaged extension (this exact failure made the webext popup load blank).
|
|
26
26
|
* One publishes a no-op browser/native variant of the same module; redirect
|
|
27
27
|
* to it instead of externalizing.
|
|
28
|
+
*
|
|
29
|
+
* When `one` is not installed at all, the redirect is skipped (with a one-line
|
|
30
|
+
* warning) so normal resolution proceeds instead of rewriting matching ids to
|
|
31
|
+
* a path that does not exist — which surfaced as a bare "No such file or
|
|
32
|
+
* directory" naming the consumer's own import. The redirect also only applies
|
|
33
|
+
* to imports made FROM one's own files (every real one-server-only import
|
|
34
|
+
* site lives in one/dist); a consumer module whose id merely contains the
|
|
35
|
+
* substring resolves normally.
|
|
28
36
|
*/
|
|
29
37
|
export declare function oneServerOnlyBrowserStub(workspaceRoot?: string): Plugin;
|
|
30
38
|
/**
|
package/types/dev.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../src/dev.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../src/dev.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAInC,MAAM,WAAW,6BAA6B;IAC5C,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,2BAA2B;IAC1C,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,wBAAgB,sBAAsB,CACpC,WAAW,CAAC,EAAE,MAAM,EAAE,EACtB,EAAE,GAAU,EAAE,GAAE,6BAAkC,SA0BnD;AAED,wBAAgB,oBAAoB,CAClC,WAAW,CAAC,EAAE,MAAM,EAAE,EACtB,EAAE,GAAU,EAAE,GAAE,2BAAgC,SA2BjD;AAED,wBAAgB,aAAa,CAAC,IAAI,GAAE,MAAM,EAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAQrF;AAGD,wBAAgB,iBAAiB,WAYhC;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA8CrF;AA8BD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,wBAAwB,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAiCvE;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,IAAI,MAAM,CASjD;AAED,cAAc,QAAQ,CAAC"}
|