vike 0.4.160 → 0.4.161
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/dist/cjs/node/cli/bin.js +5 -0
- package/dist/cjs/node/client/router.js +4 -2
- package/dist/cjs/node/plugin/plugins/autoFullBuild.js +2 -2
- package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +148 -0
- package/dist/cjs/node/plugin/plugins/buildConfig.js +42 -15
- package/dist/cjs/node/plugin/plugins/commonConfig.js +5 -13
- package/dist/cjs/node/plugin/plugins/config/stemUtils.js +1 -1
- package/dist/cjs/node/plugin/plugins/distFileNames.js +9 -1
- package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +7 -2
- package/dist/cjs/node/plugin/plugins/importBuild/index.js +4 -7
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +28 -46
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{loadFileConfigEnv.js → loadFileAtConfigTime.js} +5 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +33 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformImports.js → transformFileImports.js} +7 -7
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +21 -27
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +155 -111
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +2 -1
- package/dist/cjs/node/plugin/utils.js +3 -2
- package/dist/cjs/node/prerender/runPrerender.js +12 -5
- package/dist/cjs/node/runtime/globalContext.js +7 -4
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +2 -2
- package/dist/cjs/node/runtime/html/renderHtml.js +1 -1
- package/dist/cjs/node/runtime/html/stream.js +2 -2
- package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -2
- package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +39 -39
- package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
- package/dist/cjs/node/runtime/renderPage/{logHintForCjsEsmError.js → logErrorHint.js} +81 -43
- package/dist/cjs/node/runtime/renderPage/loggerProd.js +3 -3
- package/dist/cjs/node/runtime/utils.js +1 -1
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +53 -26
- package/dist/cjs/shared/route/executeGuardHook.js +3 -2
- package/dist/cjs/shared/utils.js +0 -1
- package/dist/cjs/utils/assertNodeVersion.js +2 -2
- package/dist/cjs/utils/{findUserPackageJsonPath.js → findFile.js} +11 -8
- package/dist/cjs/utils/isVersionOrAbove.js +29 -0
- package/dist/cjs/utils/nodeEnv.js +23 -1
- package/dist/cjs/utils/objectKeys.js +19 -3
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/cjs/utils/sorter.js +62 -1
- package/dist/esm/client/client-routing-runtime/index.d.ts +1 -1
- package/dist/esm/client/client-routing-runtime/index.js +1 -1
- package/dist/esm/node/cli/bin.js +3 -1
- package/dist/esm/node/client/router.d.ts +2 -0
- package/dist/esm/node/client/router.js +3 -1
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +2 -2
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.d.ts +13 -0
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +142 -0
- package/dist/esm/node/plugin/plugins/buildConfig.d.ts +2 -0
- package/dist/esm/node/plugin/plugins/buildConfig.js +43 -16
- package/dist/esm/node/plugin/plugins/commonConfig.js +6 -14
- package/dist/esm/node/plugin/plugins/config/stemUtils.js +2 -2
- package/dist/esm/node/plugin/plugins/distFileNames.js +9 -1
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +8 -3
- package/dist/esm/node/plugin/plugins/importBuild/index.d.ts +6 -1
- package/dist/esm/node/plugin/plugins/importBuild/index.js +4 -7
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +0 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +39 -12
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +29 -47
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{loadFileConfigEnv.js → loadFileAtConfigTime.js} +4 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.d.ts +5 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +27 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformImports.d.ts → transformFileImports.d.ts} +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformImports.js → transformFileImports.js} +6 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +20 -26
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +4 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +153 -109
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +2 -1
- package/dist/esm/node/plugin/utils.d.ts +3 -2
- package/dist/esm/node/plugin/utils.js +3 -2
- package/dist/esm/node/prerender/runPrerender.js +13 -6
- package/dist/esm/node/runtime/globalContext.js +8 -5
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +2 -2
- package/dist/esm/node/runtime/html/renderHtml.js +1 -1
- package/dist/esm/node/runtime/html/stream.js +2 -2
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -2
- package/dist/esm/node/runtime/renderPage/getHttpResponseBody.d.ts +6 -5
- package/dist/esm/node/runtime/renderPage/getHttpResponseBody.js +39 -39
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
- package/dist/esm/node/runtime/renderPage/logErrorHint.d.ts +8 -0
- package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError.js → logErrorHint.js} +80 -42
- package/dist/esm/node/runtime/renderPage/loggerProd.js +3 -3
- package/dist/esm/node/runtime/utils.d.ts +1 -1
- package/dist/esm/node/runtime/utils.js +1 -1
- package/dist/esm/shared/page-configs/Config.d.ts +1 -1
- package/dist/esm/shared/page-configs/PageConfig.d.ts +2 -0
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +53 -26
- package/dist/esm/shared/route/executeGuardHook.js +3 -2
- package/dist/esm/shared/utils.d.ts +0 -1
- package/dist/esm/shared/utils.js +0 -1
- package/dist/esm/utils/assertNodeVersion.js +2 -2
- package/dist/esm/utils/findFile.d.ts +3 -0
- package/dist/esm/utils/findFile.js +21 -0
- package/dist/esm/utils/getOutDirs.d.ts +1 -0
- package/dist/esm/utils/isVersionOrAbove.d.ts +2 -0
- package/dist/esm/utils/isVersionOrAbove.js +26 -0
- package/dist/esm/utils/nodeEnv.d.ts +4 -0
- package/dist/esm/utils/nodeEnv.js +19 -0
- package/dist/esm/utils/objectKeys.d.ts +10 -1
- package/dist/esm/utils/objectKeys.js +20 -3
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/dist/esm/utils/sorter.d.ts +59 -0
- package/dist/esm/utils/sorter.js +61 -0
- package/package.json +1 -1
- package/dist/cjs/utils/objectEntries.js +0 -8
- package/dist/esm/node/runtime/renderPage/logHintForCjsEsmError.d.ts +0 -13
- package/dist/esm/utils/findUserPackageJsonPath.d.ts +0 -2
- package/dist/esm/utils/findUserPackageJsonPath.js +0 -18
- package/dist/esm/utils/objectEntries.d.ts +0 -4
- package/dist/esm/utils/objectEntries.js +0 -5
- /package/dist/cjs/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.js +0 -0
- /package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{loadFileConfigEnv.d.ts → loadFileAtConfigTime.d.ts} +0 -0
- /package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.d.ts +0 -0
- /package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.js +0 -0
package/dist/cjs/node/cli/bin.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
const cac_1 = require("cac");
|
|
4
7
|
const path_1 = require("path");
|
|
5
8
|
const runPrerender_js_1 = require("../prerender/runPrerender.js");
|
|
6
9
|
const utils_js_1 = require("./utils.js");
|
|
10
|
+
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
7
11
|
const cli = (0, cac_1.cac)(utils_js_1.projectInfo.projectName);
|
|
8
12
|
cli
|
|
9
13
|
.command('prerender', 'Pre-render the HTML of your pages', { allowUnknownOptions: true })
|
|
@@ -30,6 +34,7 @@ function assertOptions() {
|
|
|
30
34
|
'--outDir',
|
|
31
35
|
'--configFile'
|
|
32
36
|
].includes(option), 'Unknown option: ' + option);
|
|
37
|
+
(0, utils_js_1.assertWarning)(false, `You set ${picocolors_1.default.cyan(option)}, but passing options to ${picocolors_1.default.cyan('$ vike prerender')} is deprecated: use the config file instead. See https://vike.dev/command-prerender.`, { onlyOnce: true });
|
|
33
38
|
});
|
|
34
39
|
}
|
|
35
40
|
// Listen to unknown commands
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.reload = exports.navigate = void 0;
|
|
3
|
+
exports.prefetch = exports.reload = exports.navigate = void 0;
|
|
4
4
|
const assert_js_1 = require("../../utils/assert.js");
|
|
5
5
|
// `never` to ensure package.json#exports["./client/router"].types points to type defined by the client-side code
|
|
6
6
|
const navigate = (() => warnNoEffect('navigate'));
|
|
7
7
|
exports.navigate = navigate;
|
|
8
8
|
const reload = (() => warnNoEffect('reload'));
|
|
9
9
|
exports.reload = reload;
|
|
10
|
+
const prefetch = (() => warnNoEffect('prefetch'));
|
|
11
|
+
exports.prefetch = prefetch;
|
|
10
12
|
function warnNoEffect(caller) {
|
|
11
|
-
(0, assert_js_1.assertWarning)(false, `Calling ${caller} on the server-side has no effect`, {
|
|
13
|
+
(0, assert_js_1.assertWarning)(false, `Calling ${caller}() on the server-side has no effect`, {
|
|
12
14
|
showStackTrace: true,
|
|
13
15
|
onlyOnce: false
|
|
14
16
|
});
|
|
@@ -10,7 +10,7 @@ const runPrerender_js_1 = require("../../prerender/runPrerender.js");
|
|
|
10
10
|
const getConfigVike_js_1 = require("../../shared/getConfigVike.js");
|
|
11
11
|
const isViteCliCall_js_1 = require("../shared/isViteCliCall.js");
|
|
12
12
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
13
|
-
const
|
|
13
|
+
const logErrorHint_js_1 = require("../../runtime/renderPage/logErrorHint.js");
|
|
14
14
|
let forceExit = false;
|
|
15
15
|
function autoFullBuild() {
|
|
16
16
|
let config;
|
|
@@ -88,7 +88,7 @@ async function triggerFullBuild(config, configVike, bundle) {
|
|
|
88
88
|
}
|
|
89
89
|
catch (err) {
|
|
90
90
|
console.error(err);
|
|
91
|
-
(0,
|
|
91
|
+
(0, logErrorHint_js_1.logErrorHint)(err);
|
|
92
92
|
process.exit(1);
|
|
93
93
|
}
|
|
94
94
|
if (configVike.prerender && !configVike.prerender.disableAutoRun) {
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.fixServerAssets_isEnabled = exports.fixServerAssets = void 0;
|
|
7
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const fs_1 = require("fs");
|
|
10
|
+
const utils_js_1 = require("../../utils.js");
|
|
11
|
+
const virtualFilePageConfigValuesAll_js_1 = require("../../../shared/virtual-files/virtualFilePageConfigValuesAll.js");
|
|
12
|
+
const buildConfig_js_1 = require("../buildConfig.js");
|
|
13
|
+
/**
|
|
14
|
+
* true => use workaround config.build.ssrEmitAssets
|
|
15
|
+
* false => use workaround extractAssets plugin
|
|
16
|
+
*
|
|
17
|
+
* Only used by V1 design.
|
|
18
|
+
*/
|
|
19
|
+
function fixServerAssets_isEnabled() {
|
|
20
|
+
// We currently apply the workaround iff V1 design.
|
|
21
|
+
// Shall we allow the user to toggle between the two workarounds? E.g. based on https://vike.dev/includeAssetsImportedByServer.
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
exports.fixServerAssets_isEnabled = fixServerAssets_isEnabled;
|
|
25
|
+
/** https://github.com/vikejs/vike/issues/1339 */
|
|
26
|
+
async function fixServerAssets(outDirs) {
|
|
27
|
+
const clientManifest = await loadManifest(outDirs.outDirClient);
|
|
28
|
+
const serverManifest = await loadManifest(outDirs.outDirServer);
|
|
29
|
+
const { clientManifestMod, filesToCopy } = addServerAssets(clientManifest, serverManifest);
|
|
30
|
+
await copyAssets(filesToCopy, outDirs);
|
|
31
|
+
return clientManifestMod;
|
|
32
|
+
}
|
|
33
|
+
exports.fixServerAssets = fixServerAssets;
|
|
34
|
+
async function loadManifest(outDir) {
|
|
35
|
+
const manifestFilePath = path_1.default.posix.join(outDir, buildConfig_js_1.manifestTempFile);
|
|
36
|
+
const manifestFileContent = await promises_1.default.readFile(manifestFilePath, 'utf-8');
|
|
37
|
+
(0, utils_js_1.assert)(manifestFileContent);
|
|
38
|
+
const manifest = JSON.parse(manifestFileContent);
|
|
39
|
+
(0, utils_js_1.assert)(manifest);
|
|
40
|
+
return manifest;
|
|
41
|
+
}
|
|
42
|
+
async function copyAssets(filesToCopy, { outDirClient, outDirServer }) {
|
|
43
|
+
const assetsDirServer = path_1.default.posix.join(outDirServer, 'assets');
|
|
44
|
+
if (!filesToCopy.length)
|
|
45
|
+
return;
|
|
46
|
+
(0, utils_js_1.assert)((0, fs_1.existsSync)(assetsDirServer));
|
|
47
|
+
const concurrencyLimit = (0, utils_js_1.pLimit)(10);
|
|
48
|
+
await Promise.all(filesToCopy.map((file) => concurrencyLimit(() => promises_1.default.cp(path_1.default.posix.join(outDirServer, file), path_1.default.posix.join(outDirClient, file), {
|
|
49
|
+
recursive: true
|
|
50
|
+
}))));
|
|
51
|
+
await promises_1.default.rm(assetsDirServer, { recursive: true });
|
|
52
|
+
}
|
|
53
|
+
// Add serverManifest resources to clientManifest
|
|
54
|
+
function addServerAssets(clientManifest, serverManifest) {
|
|
55
|
+
var _a, _b;
|
|
56
|
+
const entriesClient = new Map();
|
|
57
|
+
const entriesServer = new Map();
|
|
58
|
+
for (const [key, entry] of Object.entries(clientManifest)) {
|
|
59
|
+
const pageId = getPageId(key);
|
|
60
|
+
if (!pageId)
|
|
61
|
+
continue;
|
|
62
|
+
const resources = collectResources(entry, clientManifest);
|
|
63
|
+
(0, utils_js_1.assert)(!entriesClient.has(pageId));
|
|
64
|
+
entriesClient.set(pageId, { key, ...resources });
|
|
65
|
+
}
|
|
66
|
+
for (const [key, entry] of Object.entries(serverManifest)) {
|
|
67
|
+
const pageId = getPageId(key);
|
|
68
|
+
if (!pageId)
|
|
69
|
+
continue;
|
|
70
|
+
const resources = collectResources(entry, serverManifest);
|
|
71
|
+
(0, utils_js_1.assert)(!entriesServer.has(pageId));
|
|
72
|
+
entriesServer.set(pageId, resources);
|
|
73
|
+
}
|
|
74
|
+
let filesToCopy = [];
|
|
75
|
+
for (const [pageId, entryClient] of entriesClient.entries()) {
|
|
76
|
+
const cssToAdd = [];
|
|
77
|
+
const assetsToAdd = [];
|
|
78
|
+
const entryServer = entriesServer.get(pageId);
|
|
79
|
+
if (entryServer) {
|
|
80
|
+
cssToAdd.push(...entryServer.css
|
|
81
|
+
.filter((cssServer) => !entryClient.css.some((cssClient) => cssServer.hash === cssClient.hash))
|
|
82
|
+
.map((css) => css.src));
|
|
83
|
+
assetsToAdd.push(...entryServer.assets
|
|
84
|
+
.filter((assertServer) => !entryClient.assets.some((assetClient) => assertServer.hash === assetClient.hash))
|
|
85
|
+
.map((asset) => asset.src));
|
|
86
|
+
}
|
|
87
|
+
const { key } = entryClient;
|
|
88
|
+
if (cssToAdd.length) {
|
|
89
|
+
filesToCopy.push(...cssToAdd);
|
|
90
|
+
(_a = clientManifest[key]).css ?? (_a.css = []);
|
|
91
|
+
clientManifest[key].css?.push(...cssToAdd);
|
|
92
|
+
}
|
|
93
|
+
if (assetsToAdd.length) {
|
|
94
|
+
filesToCopy.push(...assetsToAdd);
|
|
95
|
+
(_b = clientManifest[key]).assets ?? (_b.assets = []);
|
|
96
|
+
clientManifest[key].assets?.push(...assetsToAdd);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const clientManifestMod = clientManifest;
|
|
100
|
+
filesToCopy = (0, utils_js_1.unique)(filesToCopy);
|
|
101
|
+
return { clientManifestMod, filesToCopy };
|
|
102
|
+
}
|
|
103
|
+
function getPageId(key) {
|
|
104
|
+
// Normalize from:
|
|
105
|
+
// ../../virtual:vike:pageConfigValuesAll:client:/pages/index
|
|
106
|
+
// to:
|
|
107
|
+
// virtual:vike:pageConfigValuesAll:client:/pages/index
|
|
108
|
+
// (This seems to be needed only for vitest tests that use Vite's build() API with an inline config.)
|
|
109
|
+
key = key.substring(key.indexOf('virtual:vike'));
|
|
110
|
+
const result = (0, virtualFilePageConfigValuesAll_js_1.isVirtualFileIdPageConfigValuesAll)(key);
|
|
111
|
+
return result && result.pageId;
|
|
112
|
+
}
|
|
113
|
+
function collectResources(entryRoot, manifest) {
|
|
114
|
+
const css = [];
|
|
115
|
+
const assets = [];
|
|
116
|
+
const entries = new Set([entryRoot]);
|
|
117
|
+
for (const entry of entries) {
|
|
118
|
+
for (const entryImport of entry.imports ?? []) {
|
|
119
|
+
entries.add(manifest[entryImport]);
|
|
120
|
+
}
|
|
121
|
+
const entryCss = entry.css ?? [];
|
|
122
|
+
if (entry.file.endsWith('.css'))
|
|
123
|
+
entryCss.push(entry.file);
|
|
124
|
+
for (const src of entryCss) {
|
|
125
|
+
const hash = getHash(src);
|
|
126
|
+
css.push({ src, hash });
|
|
127
|
+
}
|
|
128
|
+
const entryAssets = entry.assets ?? [];
|
|
129
|
+
for (const src of entryAssets) {
|
|
130
|
+
const hash = getHash(src);
|
|
131
|
+
assets.push({ src, hash });
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return { css, assets };
|
|
135
|
+
}
|
|
136
|
+
// Use the hash of resources to determine whether they are equal. We need this, otherwise we get:
|
|
137
|
+
// ```html
|
|
138
|
+
// <head>
|
|
139
|
+
// <link rel="stylesheet" type="text/css" href="/assets/static/onRenderClient.2j6TxKIB.css">
|
|
140
|
+
// <link rel="stylesheet" type="text/css" href="/assets/static/onRenderHtml.2j6TxKIB.css">
|
|
141
|
+
// </head>
|
|
142
|
+
// ```
|
|
143
|
+
function getHash(src) {
|
|
144
|
+
// src is guarenteed to end with `.[hash][extname]`, see distFileNames.ts
|
|
145
|
+
const hash = src.split('.').at(-2);
|
|
146
|
+
(0, utils_js_1.assert)(hash);
|
|
147
|
+
return hash;
|
|
148
|
+
}
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.analyzeClientEntries = exports.assertRollupInput = exports.buildConfig = void 0;
|
|
6
|
+
exports.manifestTempFile = exports.analyzeClientEntries = exports.assertRollupInput = exports.buildConfig = void 0;
|
|
7
7
|
const utils_js_1 = require("../utils.js");
|
|
8
8
|
const getVikeConfig_js_1 = require("./importUserCode/v1-design/getVikeConfig.js");
|
|
9
9
|
const helpers_js_1 = require("../../../shared/page-configs/helpers.js");
|
|
@@ -15,12 +15,17 @@ const module_1 = require("module");
|
|
|
15
15
|
const getClientEntryFilePath_js_1 = require("../../shared/getClientEntryFilePath.js");
|
|
16
16
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
17
17
|
const path_1 = __importDefault(require("path"));
|
|
18
|
+
const fixServerAssets_js_1 = require("./buildConfig/fixServerAssets.js");
|
|
19
|
+
const index_js_1 = require("./importBuild/index.js");
|
|
18
20
|
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
19
21
|
const importMetaUrl = `file://${__filename}`;
|
|
20
22
|
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
21
23
|
const manifestTempFile = '_temp_manifest.json';
|
|
24
|
+
exports.manifestTempFile = manifestTempFile;
|
|
22
25
|
function buildConfig() {
|
|
23
|
-
let
|
|
26
|
+
let isServerAssetsFixEnabled;
|
|
27
|
+
let isSsrBuild;
|
|
28
|
+
let outDirs;
|
|
24
29
|
return {
|
|
25
30
|
name: 'vike:buildConfig',
|
|
26
31
|
apply: 'build',
|
|
@@ -28,37 +33,56 @@ function buildConfig() {
|
|
|
28
33
|
configResolved: {
|
|
29
34
|
order: 'post',
|
|
30
35
|
async handler(config) {
|
|
36
|
+
assertNodeEnv();
|
|
31
37
|
assertRollupInput(config);
|
|
32
38
|
const entries = await getEntries(config);
|
|
33
39
|
(0, utils_js_1.assert)(Object.keys(entries).length > 0);
|
|
34
40
|
config.build.rollupOptions.input = (0, utils_js_1.injectRollupInputs)(entries, config);
|
|
35
41
|
addLogHook();
|
|
42
|
+
outDirs = (0, utils_js_1.getOutDirs)(config);
|
|
43
|
+
{
|
|
44
|
+
isServerAssetsFixEnabled = (0, fixServerAssets_js_1.fixServerAssets_isEnabled)() && (await (0, getVikeConfig_js_1.isV1Design)(config, false));
|
|
45
|
+
if (isServerAssetsFixEnabled) {
|
|
46
|
+
// https://github.com/vikejs/vike/issues/1339
|
|
47
|
+
config.build.ssrEmitAssets = true;
|
|
48
|
+
// Required if `ssrEmitAssets: true`, see https://github.com/vitejs/vite/pull/11430#issuecomment-1454800934
|
|
49
|
+
config.build.cssMinify = 'esbuild';
|
|
50
|
+
}
|
|
51
|
+
}
|
|
36
52
|
}
|
|
37
53
|
},
|
|
38
54
|
config(config) {
|
|
39
|
-
|
|
55
|
+
assertNodeEnv();
|
|
56
|
+
isSsrBuild = (0, utils_js_1.viteIsSSR)(config);
|
|
40
57
|
return {
|
|
41
58
|
build: {
|
|
42
59
|
outDir: (0, utils_js_1.resolveOutDir)(config),
|
|
43
|
-
manifest:
|
|
44
|
-
copyPublicDir: !
|
|
60
|
+
manifest: manifestTempFile,
|
|
61
|
+
copyPublicDir: !isSsrBuild
|
|
45
62
|
}
|
|
46
63
|
};
|
|
47
64
|
},
|
|
65
|
+
buildStart() {
|
|
66
|
+
assertNodeEnv();
|
|
67
|
+
},
|
|
48
68
|
async writeBundle(options, bundle) {
|
|
49
|
-
|
|
50
|
-
/* Fails with @vitejs/plugin-legacy because writeBundle() is called twice during the client build (once for normal client assets and a second time for legacy assets), see reproduction at https://github.com/vikejs/vike/issues/1154
|
|
51
|
-
assert(generateManifest === !!manifestEntry)
|
|
52
|
-
*/
|
|
53
|
-
if (manifestEntry) {
|
|
54
|
-
const { dir } = options;
|
|
55
|
-
(0, utils_js_1.assert)(dir);
|
|
56
|
-
const manifestFilePathOld = path_1.default.join(dir, manifestEntry.fileName);
|
|
69
|
+
if (isSsrBuild) {
|
|
57
70
|
// Ideally we'd move dist/_temp_manifest.json to dist/server/client-assets.json instead of dist/assets.json
|
|
58
71
|
// - But we can't because there is no guarentee whether dist/server/ is generated before or after dist/client/ (generating dist/server/ after dist/client/ erases dist/server/client-assets.json)
|
|
59
72
|
// - We'll able to do so once we replace `$ vite build` with `$ vike build`
|
|
60
|
-
const
|
|
61
|
-
|
|
73
|
+
const assetsJsonFilePath = path_1.default.posix.join(outDirs.outDirRoot, 'assets.json');
|
|
74
|
+
const clientManifestFilePath = path_1.default.posix.join(outDirs.outDirClient, manifestTempFile);
|
|
75
|
+
const serverManifestFilePath = path_1.default.posix.join(outDirs.outDirServer, manifestTempFile);
|
|
76
|
+
if (!isServerAssetsFixEnabled) {
|
|
77
|
+
await promises_1.default.copyFile(clientManifestFilePath, assetsJsonFilePath);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
const clientManifestMod = await (0, fixServerAssets_js_1.fixServerAssets)(outDirs);
|
|
81
|
+
await promises_1.default.writeFile(assetsJsonFilePath, JSON.stringify(clientManifestMod, null, 2), 'utf-8');
|
|
82
|
+
}
|
|
83
|
+
await promises_1.default.rm(clientManifestFilePath);
|
|
84
|
+
await promises_1.default.rm(serverManifestFilePath);
|
|
85
|
+
await (0, index_js_1.set_constant_ASSETS_MAP)(options, bundle);
|
|
62
86
|
}
|
|
63
87
|
}
|
|
64
88
|
};
|
|
@@ -230,3 +254,6 @@ function assertRollupInput(config) {
|
|
|
230
254
|
(0, utils_js_1.assertUsage)(htmlInput === undefined, `The entry ${htmlInput} of config build.rollupOptions.input is an HTML entry which is forbidden when using Vike, instead follow https://vike.dev/add`);
|
|
231
255
|
}
|
|
232
256
|
exports.assertRollupInput = assertRollupInput;
|
|
257
|
+
function assertNodeEnv() {
|
|
258
|
+
(0, utils_js_1.assertNodeEnvIsNotDev)('building');
|
|
259
|
+
}
|
|
@@ -31,7 +31,7 @@ function commonConfig() {
|
|
|
31
31
|
overrideViteDefaultPort(config);
|
|
32
32
|
/* TODO: do this after implementing vike.config.js and new setting transformLinkedDependencies (or probably a better name like transpileLinkedDependencies/bundleLinkedDependencies or something else)
|
|
33
33
|
overrideViteDefaultSsrExternal(config)
|
|
34
|
-
|
|
34
|
+
//*/
|
|
35
35
|
workaroundCI(config);
|
|
36
36
|
(0, buildConfig_js_1.assertRollupInput)(config);
|
|
37
37
|
(0, assertResolveAlias_js_1.assertResolveAlias)(config);
|
|
@@ -52,21 +52,13 @@ function overrideViteDefaultPort(config) {
|
|
|
52
52
|
(_b = config.preview).port ?? (_b.port = 3000);
|
|
53
53
|
}
|
|
54
54
|
/*
|
|
55
|
+
import { version } from 'vite'
|
|
55
56
|
function overrideViteDefaultSsrExternal(config: ResolvedConfig) {
|
|
56
|
-
if (!
|
|
57
|
+
if (!isVersionOrAbove(version, '5.0.12')) return
|
|
57
58
|
// @ts-ignore Not released yet: https://github.com/vitejs/vite/pull/10939/files#diff-5a3d42620df2c6b17e25f440ffdb67683dee7ef57317674d19f41d5f30502310L5
|
|
58
59
|
config.ssr.external ??= true
|
|
59
60
|
}
|
|
60
|
-
|
|
61
|
-
function isViteVersionWithSsrExternalTrue(): boolean {
|
|
62
|
-
const versionParts = version.split('.').map((s) => parseInt(s, 10)) as [number, number, number]
|
|
63
|
-
assert(versionParts.length === 3)
|
|
64
|
-
if (versionParts[0] > 5) return true
|
|
65
|
-
if (versionParts[1] > 0) return true
|
|
66
|
-
if (versionParts[2] >= 12) return true
|
|
67
|
-
return false
|
|
68
|
-
}
|
|
69
|
-
*/
|
|
61
|
+
//*/
|
|
70
62
|
// Workaround GitHub Action failing to access the server
|
|
71
63
|
function workaroundCI(config) {
|
|
72
64
|
var _a, _b;
|
|
@@ -76,7 +68,7 @@ function workaroundCI(config) {
|
|
|
76
68
|
}
|
|
77
69
|
}
|
|
78
70
|
function assertEsm(userViteRoot) {
|
|
79
|
-
const packageJsonPath = (0, utils_js_1.
|
|
71
|
+
const packageJsonPath = (0, utils_js_1.findFile)('package.json', userViteRoot);
|
|
80
72
|
if (!packageJsonPath)
|
|
81
73
|
return;
|
|
82
74
|
const packageJson = require_(packageJsonPath);
|
|
@@ -54,7 +54,7 @@ async function getStemPackages(userAppRootDir) {
|
|
|
54
54
|
}
|
|
55
55
|
exports.getStemPackages = getStemPackages;
|
|
56
56
|
function findUserRootDir(userAppRootDir) {
|
|
57
|
-
const userPkgJsonPath = (0, utils_js_1.
|
|
57
|
+
const userPkgJsonPath = (0, utils_js_1.findFile)('package.json', userAppRootDir);
|
|
58
58
|
(0, utils_js_1.assertUsage)(userPkgJsonPath, `Couldn't find package.json in any parent directory starting from ${userAppRootDir}`);
|
|
59
59
|
return (0, utils_js_1.toPosixPath)(path_1.default.dirname(userPkgJsonPath));
|
|
60
60
|
}
|
|
@@ -24,9 +24,17 @@ function distFileNames() {
|
|
|
24
24
|
if (!('chunkFileNames' in rollupOutput)) {
|
|
25
25
|
rollupOutput.chunkFileNames = (chunkInfo) => getChunkFileName(chunkInfo, config);
|
|
26
26
|
}
|
|
27
|
-
if (!('
|
|
27
|
+
if (!('assetFileNames' in rollupOutput)) {
|
|
28
28
|
rollupOutput.assetFileNames = (chunkInfo) => getAssetFileName(chunkInfo, config);
|
|
29
29
|
}
|
|
30
|
+
else {
|
|
31
|
+
// If a user needs this:
|
|
32
|
+
// - assertUsage() that the naming provided by the user ends with `.[hash][extname]`
|
|
33
|
+
// - It's needed for getHash() of fixServerAssets()
|
|
34
|
+
// - Asset URLs should always contain a hash: it's paramount for caching assets.
|
|
35
|
+
// - If rollupOutput.assetFileNames is a function then use a wrapper function to apply the assertUsage()
|
|
36
|
+
(0, utils_js_1.assertUsage)(false, "Setting config.build.rollupOptions.output.assetFileNames is currently forbidden. (It's possible to support, thus contact a maintainer if you need this.)");
|
|
37
|
+
}
|
|
30
38
|
});
|
|
31
39
|
}
|
|
32
40
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
//
|
|
3
|
-
// -
|
|
2
|
+
// Remove this workaround if the other workaround config.build.ssrEmitAssets turns out to be reliable.
|
|
3
|
+
// - Remove this file then revert this commit: https://github.com/vikejs/vike/commit/805a18974f13420a78fcc30fdd676696e405c3ca
|
|
4
4
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
5
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
6
|
};
|
|
@@ -13,6 +13,8 @@ const isAsset_js_1 = require("../shared/isAsset.js");
|
|
|
13
13
|
const parseEsModule_js_1 = require("../shared/parseEsModule.js");
|
|
14
14
|
const removeSourceMap_js_1 = require("../shared/removeSourceMap.js");
|
|
15
15
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
16
|
+
const fixServerAssets_js_1 = require("./buildConfig/fixServerAssets.js");
|
|
17
|
+
const getVikeConfig_js_1 = require("./importUserCode/v1-design/getVikeConfig.js");
|
|
16
18
|
const extractAssetsRE = /(\?|&)extractAssets(?:&|$)/;
|
|
17
19
|
exports.extractAssetsRE = extractAssetsRE;
|
|
18
20
|
const rawRE = /(\?|&)raw(?:&|$)/;
|
|
@@ -24,6 +26,7 @@ const debugEnabled = (0, utils_js_1.isDebugEnabled)(debugNamespace);
|
|
|
24
26
|
function extractAssetsPlugin() {
|
|
25
27
|
let config;
|
|
26
28
|
let configVike;
|
|
29
|
+
let isServerAssetsFixEnabled;
|
|
27
30
|
return [
|
|
28
31
|
// This plugin removes all JavaScript from server-side only code, so that only CSS imports remains. (And also satic files imports e.g. `import logoURL from './logo.svg.js'`).
|
|
29
32
|
{
|
|
@@ -35,6 +38,7 @@ function extractAssetsPlugin() {
|
|
|
35
38
|
if (!extractAssetsRE.test(id)) {
|
|
36
39
|
return;
|
|
37
40
|
}
|
|
41
|
+
(0, utils_js_1.assert)(!isServerAssetsFixEnabled);
|
|
38
42
|
(0, utils_js_1.assert)(configVike.includeAssetsImportedByServer);
|
|
39
43
|
(0, utils_js_1.assert)(!(0, utils_js_1.viteIsSSR_options)(options));
|
|
40
44
|
const importStatements = await (0, parseEsModule_js_1.getImportStatements)(src);
|
|
@@ -132,6 +136,7 @@ function extractAssetsPlugin() {
|
|
|
132
136
|
async configResolved(config_) {
|
|
133
137
|
configVike = await (0, getConfigVike_js_1.getConfigVike)(config_);
|
|
134
138
|
config = config_;
|
|
139
|
+
isServerAssetsFixEnabled = (0, fixServerAssets_js_1.fixServerAssets_isEnabled)() && (await (0, getVikeConfig_js_1.isV1Design)(config, false));
|
|
135
140
|
},
|
|
136
141
|
load(id) {
|
|
137
142
|
if (!(0, utils_js_1.isVirtualFileId)(id))
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.importBuild = void 0;
|
|
6
|
+
exports.set_constant_ASSETS_MAP = exports.importBuild = void 0;
|
|
7
7
|
const plugin_js_1 = require("@brillout/vite-plugin-server-entry/plugin.js");
|
|
8
8
|
const utils_js_1 = require("../../utils.js");
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
@@ -26,11 +26,6 @@ function importBuild() {
|
|
|
26
26
|
async configResolved(config_) {
|
|
27
27
|
config = config_;
|
|
28
28
|
configVike = await (0, getConfigVike_js_1.getConfigVike)(config);
|
|
29
|
-
},
|
|
30
|
-
async writeBundle(options, bundle) {
|
|
31
|
-
if (!(0, utils_js_1.viteIsSSR)(config))
|
|
32
|
-
return;
|
|
33
|
-
await replace_ASSETS_MAP(options, bundle);
|
|
34
29
|
}
|
|
35
30
|
},
|
|
36
31
|
...(0, plugin_js_1.serverEntryPlugin)({
|
|
@@ -64,7 +59,8 @@ function getEntryCode(config, configVike) {
|
|
|
64
59
|
].join('\n');
|
|
65
60
|
return importerCode;
|
|
66
61
|
}
|
|
67
|
-
|
|
62
|
+
/** Set the value of the ASSETS_MAP constant inside dist/server/entry.js (or dist/server/index.js) */
|
|
63
|
+
async function set_constant_ASSETS_MAP(options, bundle) {
|
|
68
64
|
const { dir } = options;
|
|
69
65
|
(0, utils_js_1.assert)(dir);
|
|
70
66
|
// This will probably fail with @vitejs/plugin-legacy
|
|
@@ -80,6 +76,7 @@ async function replace_ASSETS_MAP(options, bundle) {
|
|
|
80
76
|
(0, utils_js_1.assert)(serverEntryFileContentPatched !== serverEntryFileContent);
|
|
81
77
|
await promises_1.default.writeFile(serverEntryFilePath, serverEntryFileContentPatched);
|
|
82
78
|
}
|
|
79
|
+
exports.set_constant_ASSETS_MAP = set_constant_ASSETS_MAP;
|
|
83
80
|
function getImportPath(config) {
|
|
84
81
|
// We resolve filePathAbsolute even if we don't use it: we use require.resolve() as an assertion that the relative path is correct
|
|
85
82
|
const filePathAbsolute = (0, utils_js_1.toPosixPath)(
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js
CHANGED
|
@@ -49,11 +49,7 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
|
|
|
49
49
|
p = (0, utils_js_1.toPosixPath)(p);
|
|
50
50
|
(0, utils_js_1.assert)(!p.startsWith(userRootDir));
|
|
51
51
|
const filePathRelativeToUserRootDir = path_1.default.posix.join('/', p);
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
filePathRelativeToUserRootDir,
|
|
55
|
-
filePathAbsoluteFilesystem
|
|
56
|
-
};
|
|
52
|
+
return { filePathRelativeToUserRootDir };
|
|
57
53
|
});
|
|
58
54
|
return plusFiles;
|
|
59
55
|
}
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js
CHANGED
|
@@ -3,34 +3,37 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getLogicalPath = exports.applyFilesystemRoutingRootEffect = exports.isGlobalLocation = exports.sortAfterInheritanceOrder = exports.getLocationId = exports.isInherited = exports.getFilesystemRouteDefinedBy = exports.getFilesystemRouteString = void 0;
|
|
4
4
|
const utils_js_1 = require("../../../../utils.js");
|
|
5
5
|
/**
|
|
6
|
-
* getLocationId('/pages/some-page/+Page.js') => '/pages/some-page'
|
|
7
|
-
* getLocationId('/
|
|
8
|
-
*
|
|
6
|
+
* `getLocationId('/pages/some-page/+Page.js')` => `'/pages/some-page'`
|
|
7
|
+
* `getLocationId('/renderer/+config.js')` => `'/renderer'`
|
|
8
|
+
*
|
|
9
|
+
* The value `locationId` is always a user-land path, because Filesystem Routing/Inheritance only applies to the user-land (Vike never uses Filesystem Routing/Inheritance for `node_modules/**`).
|
|
9
10
|
*/
|
|
10
|
-
function getLocationId(
|
|
11
|
-
|
|
11
|
+
function getLocationId(
|
|
12
|
+
// We always determine `locationId` from a real user-land file: the `locationId` for Vike extensions is the `locationId` of the the user's `+config.h.js` that extends the Vike extension.
|
|
13
|
+
filePathRelativeToUserRootDir) {
|
|
14
|
+
(0, utils_js_1.assertPosixPath)(filePathRelativeToUserRootDir);
|
|
15
|
+
(0, utils_js_1.assert)(filePathRelativeToUserRootDir.startsWith('/'));
|
|
16
|
+
const locationId = removeFilename(filePathRelativeToUserRootDir);
|
|
12
17
|
assertLocationId(locationId);
|
|
13
18
|
return locationId;
|
|
14
19
|
}
|
|
15
20
|
exports.getLocationId = getLocationId;
|
|
16
|
-
/**
|
|
21
|
+
/** Filesystem Routing: get the URL */
|
|
17
22
|
function getFilesystemRouteString(locationId) {
|
|
18
23
|
return getLogicalPath(locationId, ['renderer', 'pages', 'src', 'index']);
|
|
19
24
|
}
|
|
20
25
|
exports.getFilesystemRouteString = getFilesystemRouteString;
|
|
21
|
-
/**
|
|
22
|
-
function getInheritanceRoot(
|
|
23
|
-
return getLogicalPath(
|
|
26
|
+
/** Filesystem Inheritance: get the apply root */
|
|
27
|
+
function getInheritanceRoot(locationId) {
|
|
28
|
+
return getLogicalPath(locationId, ['renderer']);
|
|
24
29
|
}
|
|
25
30
|
/**
|
|
26
31
|
* getLogicalPath('/pages/some-page', ['pages']) => '/some-page'
|
|
27
|
-
* getLogicalPath('some-npm-pkg/renderer', ['renderer']) => '/'
|
|
28
32
|
*/
|
|
29
|
-
function getLogicalPath(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return someDir;
|
|
33
|
+
function getLogicalPath(locationId, removeDirs) {
|
|
34
|
+
let logicalPath = removeDirectories(locationId, removeDirs);
|
|
35
|
+
assertIsPath(logicalPath);
|
|
36
|
+
return logicalPath;
|
|
34
37
|
}
|
|
35
38
|
exports.getLogicalPath = getLogicalPath;
|
|
36
39
|
/** Whether configs defined in `locationId` apply in every `locationIds` */
|
|
@@ -39,6 +42,10 @@ function isGlobalLocation(locationId, locationIds) {
|
|
|
39
42
|
}
|
|
40
43
|
exports.isGlobalLocation = isGlobalLocation;
|
|
41
44
|
function sortAfterInheritanceOrder(locationId1, locationId2, locationIdPage) {
|
|
45
|
+
assertLocationId(locationId1);
|
|
46
|
+
assertLocationId(locationId2);
|
|
47
|
+
if (locationId1 === locationId2)
|
|
48
|
+
return 0;
|
|
42
49
|
const inheritanceRoot1 = getInheritanceRoot(locationId1);
|
|
43
50
|
const inheritanceRoot2 = getInheritanceRoot(locationId2);
|
|
44
51
|
const inheritanceRootPage = getInheritanceRoot(locationIdPage);
|
|
@@ -54,15 +61,10 @@ function sortAfterInheritanceOrder(locationId1, locationId2, locationIdPage) {
|
|
|
54
61
|
(0, utils_js_1.assert)(inheritanceRoot1.length !== inheritanceRoot2.length);
|
|
55
62
|
return (0, utils_js_1.higherFirst)((inheritanceRoot) => inheritanceRoot.length)(inheritanceRoot1, inheritanceRoot2);
|
|
56
63
|
}
|
|
57
|
-
// Should be true since we aggregate interface files by locationId
|
|
58
|
-
(0, utils_js_1.assert)(locationId1 !== locationId2);
|
|
59
64
|
// locationId1 first, i.e. `indexOf(locationId1) < indexOf(locationId2)`
|
|
60
65
|
const locationId1First = -1;
|
|
61
66
|
// locationId2 first, i.e. `indexOf(locationId2) < indexOf(locationId1)`
|
|
62
67
|
const locationId2First = 1;
|
|
63
|
-
if (locationIsNpmPackage(locationId1) !== locationIsNpmPackage(locationId2)) {
|
|
64
|
-
return locationIsNpmPackage(locationId1) ? locationId2First : locationId1First;
|
|
65
|
-
}
|
|
66
68
|
if (locationIsRendererDir(locationId1) !== locationIsRendererDir(locationId2)) {
|
|
67
69
|
return locationIsRendererDir(locationId1) ? locationId2First : locationId1First;
|
|
68
70
|
}
|
|
@@ -74,9 +76,6 @@ function sortAfterInheritanceOrder(locationId1, locationId2, locationIdPage) {
|
|
|
74
76
|
return locationId1 > locationId2 ? locationId1First : locationId2First;
|
|
75
77
|
}
|
|
76
78
|
exports.sortAfterInheritanceOrder = sortAfterInheritanceOrder;
|
|
77
|
-
function locationIsNpmPackage(locationId) {
|
|
78
|
-
return !locationId.startsWith('/');
|
|
79
|
-
}
|
|
80
79
|
function locationIsRendererDir(locationId) {
|
|
81
80
|
return locationId.split('/').includes('renderer');
|
|
82
81
|
}
|
|
@@ -87,19 +86,6 @@ function isInherited(locationId1, locationId2) {
|
|
|
87
86
|
return startsWith(inheritanceRoot2, inheritanceRoot1);
|
|
88
87
|
}
|
|
89
88
|
exports.isInherited = isInherited;
|
|
90
|
-
function removeNpmPackageName(somePath) {
|
|
91
|
-
if (!(0, utils_js_1.isNpmPackageImport)(somePath)) {
|
|
92
|
-
(0, utils_js_1.assert)(somePath.startsWith('/'));
|
|
93
|
-
return somePath;
|
|
94
|
-
}
|
|
95
|
-
const importPath = (0, utils_js_1.getNpmPackageImportPath)(somePath);
|
|
96
|
-
if (!importPath)
|
|
97
|
-
return '/';
|
|
98
|
-
(0, utils_js_1.assertPosixPath)(importPath);
|
|
99
|
-
(0, utils_js_1.assert)(!importPath.startsWith('/'));
|
|
100
|
-
somePath = '/' + importPath;
|
|
101
|
-
return somePath;
|
|
102
|
-
}
|
|
103
89
|
function removeDirectories(somePath, removeDirs) {
|
|
104
90
|
(0, utils_js_1.assertPosixPath)(somePath);
|
|
105
91
|
somePath = somePath
|
|
@@ -110,17 +96,13 @@ function removeDirectories(somePath, removeDirs) {
|
|
|
110
96
|
somePath = '/';
|
|
111
97
|
return somePath;
|
|
112
98
|
}
|
|
113
|
-
function removeFilename(
|
|
114
|
-
|
|
115
|
-
(0, utils_js_1.assert)(filePathAbsoluteVite.startsWith('/') || (0, utils_js_1.isNpmPackageImport)(filePathAbsoluteVite));
|
|
99
|
+
function removeFilename(filePathRelativeToUserRootDir) {
|
|
100
|
+
const filePathParts = filePathRelativeToUserRootDir.split('/');
|
|
116
101
|
{
|
|
117
|
-
const filename =
|
|
118
|
-
|
|
119
|
-
(0, utils_js_1.assert)(optional);
|
|
120
|
-
return filePathAbsoluteVite;
|
|
121
|
-
}
|
|
102
|
+
const filename = filePathParts.slice(-1)[0];
|
|
103
|
+
(0, utils_js_1.assert)(filename.includes('.'));
|
|
122
104
|
}
|
|
123
|
-
let locationId =
|
|
105
|
+
let locationId = filePathParts.slice(0, -1).join('/');
|
|
124
106
|
if (locationId === '')
|
|
125
107
|
locationId = '/';
|
|
126
108
|
assertLocationId(locationId);
|
|
@@ -144,7 +126,7 @@ function applyFilesystemRoutingRootEffect(routeFilesystem, filesystemRoutingRoot
|
|
|
144
126
|
}
|
|
145
127
|
exports.applyFilesystemRoutingRootEffect = applyFilesystemRoutingRootEffect;
|
|
146
128
|
function assertLocationId(locationId) {
|
|
147
|
-
(0, utils_js_1.assert)(locationId.startsWith('/')
|
|
129
|
+
(0, utils_js_1.assert)(locationId.startsWith('/'));
|
|
148
130
|
(0, utils_js_1.assert)(!locationId.endsWith('/') || locationId === '/');
|
|
149
131
|
}
|
|
150
132
|
function assertIsPath(logicalPath) {
|