vike 0.4.186 → 0.4.188-commit-373ae21
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/plugin/index.js +3 -1
- package/dist/cjs/node/plugin/plugins/distFileNames.js +44 -3
- package/dist/cjs/node/plugin/plugins/envVars.js +1 -1
- package/dist/cjs/node/plugin/plugins/fileEnv.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +1 -1
- package/dist/cjs/node/plugin/plugins/workaroundCssModuleHmr.js +16 -0
- package/dist/cjs/node/plugin/shared/getFilePath.js +55 -25
- package/dist/cjs/node/plugin/utils.js +1 -1
- package/dist/cjs/node/prerender/runPrerender.js +1 -1
- package/dist/cjs/node/prerender/utils.js +1 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/isFilePathAbsoluteFilesystem.js +60 -0
- package/dist/esm/node/plugin/index.js +3 -1
- package/dist/esm/node/plugin/plugins/distFileNames.js +45 -4
- package/dist/esm/node/plugin/plugins/envVars.js +2 -2
- package/dist/esm/node/plugin/plugins/fileEnv.js +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +2 -2
- package/dist/esm/node/plugin/plugins/workaroundCssModuleHmr.d.ts +3 -0
- package/dist/esm/node/plugin/plugins/workaroundCssModuleHmr.js +13 -0
- package/dist/esm/node/plugin/shared/getFilePath.d.ts +7 -3
- package/dist/esm/node/plugin/shared/getFilePath.js +55 -25
- package/dist/esm/node/plugin/utils.d.ts +1 -1
- package/dist/esm/node/plugin/utils.js +1 -1
- package/dist/esm/node/prerender/runPrerender.js +2 -2
- package/dist/esm/node/prerender/utils.d.ts +1 -1
- package/dist/esm/node/prerender/utils.js +1 -1
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/isFilePathAbsoluteFilesystem.d.ts +14 -0
- package/dist/esm/utils/isFilePathAbsoluteFilesystem.js +54 -0
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +1 -1
- package/dist/cjs/utils/assertPathFilesystemAbsolute.js +0 -39
- package/dist/esm/utils/assertPathFilesystemAbsolute.d.ts +0 -6
- package/dist/esm/utils/assertPathFilesystemAbsolute.js +0 -33
|
@@ -30,6 +30,7 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
|
30
30
|
const fileEnv_js_1 = require("./plugins/fileEnv.js");
|
|
31
31
|
const getPageAssets_js_1 = require("../runtime/renderPage/getPageAssets.js");
|
|
32
32
|
const resolveClientEntriesDev_js_1 = require("./resolveClientEntriesDev.js");
|
|
33
|
+
const workaroundCssModuleHmr_js_1 = require("./plugins/workaroundCssModuleHmr.js");
|
|
33
34
|
(0, utils_js_2.assertNodeEnv_onVikePluginLoad)();
|
|
34
35
|
(0, utils_js_2.markEnvAsVikePluginLoaded)();
|
|
35
36
|
assertViteVersion();
|
|
@@ -54,7 +55,8 @@ function plugin(vikeConfig) {
|
|
|
54
55
|
...(0, index_js_4.importBuild)(),
|
|
55
56
|
(0, baseUrls_js_1.baseUrls)(vikeConfig),
|
|
56
57
|
(0, envVars_js_1.envVarsPlugin)(),
|
|
57
|
-
(0, fileEnv_js_1.fileEnv)()
|
|
58
|
+
(0, fileEnv_js_1.fileEnv)(),
|
|
59
|
+
(0, workaroundCssModuleHmr_js_1.workaroundCssModuleHmr)()
|
|
58
60
|
];
|
|
59
61
|
return plugins;
|
|
60
62
|
}
|
|
@@ -9,7 +9,9 @@ exports.distFileNames = void 0;
|
|
|
9
9
|
// - Blocker: https://github.com/rollup/rollup/issues/4724
|
|
10
10
|
const utils_js_1 = require("../utils.js");
|
|
11
11
|
const path_1 = __importDefault(require("path"));
|
|
12
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
12
13
|
const getAssetsDir_js_1 = require("../shared/getAssetsDir.js");
|
|
14
|
+
const getFilePath_js_1 = require("../shared/getFilePath.js");
|
|
13
15
|
function distFileNames() {
|
|
14
16
|
return {
|
|
15
17
|
name: 'vike:distFileNames',
|
|
@@ -39,16 +41,52 @@ function distFileNames() {
|
|
|
39
41
|
{
|
|
40
42
|
const manualChunksOriginal = rollupOutput.manualChunks;
|
|
41
43
|
rollupOutput.manualChunks = function (id, ...args) {
|
|
42
|
-
if (id.endsWith('.css') && id.includes('node_modules'))
|
|
43
|
-
return 'vendor';
|
|
44
44
|
if (manualChunksOriginal) {
|
|
45
45
|
if ((0, utils_js_1.isCallable)(manualChunksOriginal)) {
|
|
46
|
-
|
|
46
|
+
const result = manualChunksOriginal.call(this, id, ...args);
|
|
47
|
+
if (result !== undefined)
|
|
48
|
+
return result;
|
|
47
49
|
}
|
|
48
50
|
else {
|
|
49
51
|
(0, utils_js_1.assertUsage)(false, "The Vite's configuration build.rollupOptions.output.manualChunks must be a function. Reach out if you need to set it to another value.");
|
|
50
52
|
}
|
|
51
53
|
}
|
|
54
|
+
// Disable CSS bundling to workaround https://github.com/vikejs/vike/issues/1815
|
|
55
|
+
if (id.endsWith('.css')) {
|
|
56
|
+
if ((0, utils_js_1.isFilePathAbsolute)(id)) {
|
|
57
|
+
(0, utils_js_1.assertPosixPath)(id);
|
|
58
|
+
(0, getFilePath_js_1.assertModuleId)(id);
|
|
59
|
+
let name;
|
|
60
|
+
const isNodeModules = id.match(/node_modules\/([^\/]+)\/(?!.*node_modules)/);
|
|
61
|
+
if (isNodeModules) {
|
|
62
|
+
name = isNodeModules[1];
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
const filePath = (0, getFilePath_js_1.getModuleFilePathAbsolute)(id, config);
|
|
66
|
+
name = filePath;
|
|
67
|
+
name = name.split('.').slice(0, -1).join('.'); // remove file extension
|
|
68
|
+
name = name.split('/').join('_');
|
|
69
|
+
}
|
|
70
|
+
// Make fileHash the same between local development and CI
|
|
71
|
+
const idStable = path_1.default.posix.relative(config.root, id);
|
|
72
|
+
// Don't remove `?` queries because each `id` should belong to a unique bundle.
|
|
73
|
+
const hash = getIdHash(idStable);
|
|
74
|
+
return `${name}-${hash}`;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
let name;
|
|
78
|
+
const isVirtualModule = id.match(/virtual:([^:]+):/);
|
|
79
|
+
if (!isVirtualModule) {
|
|
80
|
+
name = 'style';
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
name = isVirtualModule[1];
|
|
84
|
+
(0, utils_js_1.assert)(name);
|
|
85
|
+
}
|
|
86
|
+
const hash = getIdHash(id);
|
|
87
|
+
return `${name}-${hash}`;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
52
90
|
};
|
|
53
91
|
}
|
|
54
92
|
});
|
|
@@ -56,6 +94,9 @@ function distFileNames() {
|
|
|
56
94
|
};
|
|
57
95
|
}
|
|
58
96
|
exports.distFileNames = distFileNames;
|
|
97
|
+
function getIdHash(id) {
|
|
98
|
+
return crypto_1.default.createHash('md5').update(id).digest('hex').slice(0, 8);
|
|
99
|
+
}
|
|
59
100
|
function getAssetFileName(assetInfo, config) {
|
|
60
101
|
const assetsDir = (0, getAssetsDir_js_1.getAssetsDir)(config);
|
|
61
102
|
const dir = assetsDir + '/static';
|
|
@@ -51,7 +51,7 @@ function envVarsPlugin() {
|
|
|
51
51
|
if (isPrivate && isClientSide) {
|
|
52
52
|
if (!envStatementRegEx.test(code))
|
|
53
53
|
return;
|
|
54
|
-
const modulePath = (0, getFilePath_js_1.
|
|
54
|
+
const modulePath = (0, getFilePath_js_1.getModuleFilePathAbsolute)(id, config);
|
|
55
55
|
const errMsgAddendum = isBuild ? '' : ' (Vike will prevent your app from building for production)';
|
|
56
56
|
const keyPublic = `${PUBLIC_ENV_PREFIX}${envName}`;
|
|
57
57
|
const errMsg = `${envStatement} is used in client-side file ${modulePath} which means that the environment variable ${envName} will be included in client-side bundles and, therefore, ${envName} will be publicly exposed which can be a security leak${errMsgAddendum}. Use ${envStatement} only in server-side files, or rename ${envName} to ${keyPublic}, see https://vike.dev/env`;
|
|
@@ -67,7 +67,7 @@ function fileEnv() {
|
|
|
67
67
|
return;
|
|
68
68
|
// Show error message
|
|
69
69
|
let errMsg;
|
|
70
|
-
let modulePathPretty = (0, getFilePath_js_1.
|
|
70
|
+
let modulePathPretty = (0, getFilePath_js_1.getModuleFilePathAbsolute)(moduleId, config);
|
|
71
71
|
modulePathPretty = modulePathPretty.replaceAll(suffix, picocolors_1.default.bold(suffix));
|
|
72
72
|
errMsg = `${(0, utils_js_1.capitalizeFirstLetter)(envExpect)}-only file ${modulePathPretty} (https://vike.dev/file-env) imported on the ${envActual}-side`;
|
|
73
73
|
if (importer &&
|
|
@@ -75,7 +75,7 @@ function fileEnv() {
|
|
|
75
75
|
!importer.includes('virtual:vike:') &&
|
|
76
76
|
// I don't know why and who sets importer to '<stdin>' (I guess Vite?)
|
|
77
77
|
importer !== '<stdin>') {
|
|
78
|
-
const importerPath = (0, getFilePath_js_1.
|
|
78
|
+
const importerPath = (0, getFilePath_js_1.getModuleFilePathAbsolute)(importer, config);
|
|
79
79
|
errMsg += ` by ${importerPath}`;
|
|
80
80
|
}
|
|
81
81
|
if (isDev) {
|
|
@@ -126,7 +126,7 @@ function isVikeConfigModule(filePathAbsoluteFilesystem) {
|
|
|
126
126
|
}
|
|
127
127
|
function reloadConfig(filePath, config, op) {
|
|
128
128
|
{
|
|
129
|
-
const filePathToShowToUserResolved = (0, getFilePath_js_1.
|
|
129
|
+
const filePathToShowToUserResolved = (0, getFilePath_js_1.getModuleFilePathAbsolute)(filePath, config);
|
|
130
130
|
const msg = `${op} ${picocolors_1.default.dim(filePathToShowToUserResolved)}`;
|
|
131
131
|
(0, loggerNotProd_js_1.logConfigInfo)(msg, 'info');
|
|
132
132
|
}
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js
CHANGED
|
@@ -37,7 +37,7 @@ function resolvePointerImport(pointerImportData, importerFilePath, userRootDir)
|
|
|
37
37
|
// - An npm package import
|
|
38
38
|
// - importPath cannot be a path alias (since esbuild resolves path aliases, see transpileAndExecuteFile.ts)
|
|
39
39
|
(0, utils_js_1.assertPosixPath)(importPath);
|
|
40
|
-
if (importPath.startsWith('.') || (0, utils_js_1.
|
|
40
|
+
if (importPath.startsWith('.') || (0, utils_js_1.isFilePathAbsolute)(importPath)) {
|
|
41
41
|
if (importPath.startsWith('.')) {
|
|
42
42
|
(0, utils_js_1.assert)(importPath.startsWith('./') || importPath.startsWith('../'));
|
|
43
43
|
}
|
|
@@ -123,7 +123,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
123
123
|
// isNpmPackageImport(str, { cannotBePathAlias: true })
|
|
124
124
|
// assertIsNpmPackageImport()
|
|
125
125
|
// ```
|
|
126
|
-
(0, utils_js_1.
|
|
126
|
+
(0, utils_js_1.assertFilePathAbsoluteFilesystem)(importPathResolved);
|
|
127
127
|
// vike-{react,vue,solid} follow the convention that their config export resolves to a file named +config.js
|
|
128
128
|
// - This is temporary, see comment below.
|
|
129
129
|
const isVikeExtensionConfigImport = importPathResolved.endsWith('+config.js');
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.workaroundCssModuleHmr = void 0;
|
|
4
|
+
function workaroundCssModuleHmr() {
|
|
5
|
+
return {
|
|
6
|
+
name: 'vike:workaroundCssModuleHmr',
|
|
7
|
+
handleHotUpdate(ctx) {
|
|
8
|
+
// prevent full reload due to non self-accepting css module.
|
|
9
|
+
// here only "?direct" module should be filtered out as it doesn't have a parent module.
|
|
10
|
+
if (ctx.file.includes('module.css')) {
|
|
11
|
+
return ctx.modules.filter((m) => !m.id?.includes('?direct'));
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
exports.workaroundCssModuleHmr = workaroundCssModuleHmr;
|
|
@@ -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.
|
|
6
|
+
exports.assertModuleId = exports.cleanFilePathUnkown = exports.getModuleFilePathRelative = exports.getModuleFilePathAbsolute = exports.getFilePathToShowToUserFromUnkown = exports.getFilePathAbsoluteUserRootDir = exports.getFilePathUnresolved = exports.getFilePathResolved = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const utils_js_1 = require("../utils.js");
|
|
9
9
|
function getFilePathResolved(args) {
|
|
@@ -19,7 +19,7 @@ function getFilePathResolved(args) {
|
|
|
19
19
|
filePathAbsoluteFilesystem = getFilePathAbsoluteUserFilesystem({ filePathAbsoluteUserRootDir, userRootDir });
|
|
20
20
|
}
|
|
21
21
|
(0, utils_js_1.assert)(filePathAbsoluteFilesystem);
|
|
22
|
-
(0, utils_js_1.
|
|
22
|
+
(0, utils_js_1.assertFilePathAbsoluteFilesystem)(filePathAbsoluteFilesystem);
|
|
23
23
|
const filePathToShowToUserResolved = filePathAbsoluteUserRootDir || filePathAbsoluteFilesystem;
|
|
24
24
|
(0, utils_js_1.assert)(filePathToShowToUserResolved);
|
|
25
25
|
(0, utils_js_1.assertPosixPath)(filePathAbsoluteFilesystem);
|
|
@@ -70,47 +70,77 @@ exports.getFilePathUnresolved = getFilePathUnresolved;
|
|
|
70
70
|
function getFilePathAbsoluteUserFilesystem({ filePathAbsoluteUserRootDir, userRootDir }) {
|
|
71
71
|
(0, utils_js_1.assertPosixPath)(filePathAbsoluteUserRootDir);
|
|
72
72
|
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
73
|
-
(0, utils_js_1.
|
|
73
|
+
(0, utils_js_1.assertFilePathAbsoluteFilesystem)(userRootDir);
|
|
74
74
|
const filePathAbsoluteFilesystem = path_1.default.posix.join(userRootDir, filePathAbsoluteUserRootDir);
|
|
75
|
-
(0, utils_js_1.
|
|
75
|
+
(0, utils_js_1.assertFilePathAbsoluteFilesystem)(userRootDir);
|
|
76
76
|
return filePathAbsoluteFilesystem;
|
|
77
77
|
}
|
|
78
78
|
function getFilePathAbsoluteUserRootDir({ filePathAbsoluteFilesystem, userRootDir }) {
|
|
79
|
+
const { filePathAbsoluteUserRootDir } = getFilePathRelative({
|
|
80
|
+
filePathAbsoluteFilesystem,
|
|
81
|
+
userRootDir
|
|
82
|
+
});
|
|
83
|
+
return filePathAbsoluteUserRootDir;
|
|
84
|
+
}
|
|
85
|
+
exports.getFilePathAbsoluteUserRootDir = getFilePathAbsoluteUserRootDir;
|
|
86
|
+
function getFilePathRelative({ filePathAbsoluteFilesystem, userRootDir }) {
|
|
79
87
|
(0, utils_js_1.assertPosixPath)(filePathAbsoluteFilesystem);
|
|
80
88
|
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
81
|
-
(0, utils_js_1.
|
|
82
|
-
(0, utils_js_1.
|
|
83
|
-
const
|
|
89
|
+
(0, utils_js_1.assertFilePathAbsoluteFilesystem)(filePathAbsoluteFilesystem);
|
|
90
|
+
(0, utils_js_1.assertFilePathAbsoluteFilesystem)(userRootDir);
|
|
91
|
+
const filePathRelativeUserRootDir = path_1.default.posix.relative(userRootDir, filePathAbsoluteFilesystem);
|
|
84
92
|
if (!filePathAbsoluteFilesystem.startsWith(userRootDir)) {
|
|
85
|
-
(0, utils_js_1.assert)(
|
|
86
|
-
return
|
|
93
|
+
(0, utils_js_1.assert)(filePathRelativeUserRootDir.startsWith('../'));
|
|
94
|
+
return {
|
|
95
|
+
filePathAbsoluteUserRootDir: null,
|
|
96
|
+
filePathRelativeUserRootDir
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
(0, utils_js_1.assert)(!filePathRelativeUserRootDir.startsWith('/') &&
|
|
101
|
+
/* Not true if filePathRelative starts with a hidden directory (i.e. a directory with a name that starts with `.`)
|
|
102
|
+
!filePathRelative.startsWith('.') &&
|
|
103
|
+
*/
|
|
104
|
+
!filePathRelativeUserRootDir.startsWith('./') &&
|
|
105
|
+
!filePathRelativeUserRootDir.startsWith('../'));
|
|
106
|
+
const filePathAbsoluteUserRootDir = `/${filePathRelativeUserRootDir}`;
|
|
107
|
+
(0, utils_js_1.assert)(filePathAbsoluteUserRootDir === getFilePathAbsoluteUserRootDir2(filePathAbsoluteFilesystem, userRootDir));
|
|
108
|
+
return { filePathAbsoluteUserRootDir, filePathRelativeUserRootDir };
|
|
87
109
|
}
|
|
88
|
-
(0, utils_js_1.assert)(!filePathRelative.startsWith('/') &&
|
|
89
|
-
/* Not true if filePathRelative starts with a hidden directory (i.e. a directory with a name that starts with `.`)
|
|
90
|
-
!filePathRelative.startsWith('.') &&
|
|
91
|
-
*/
|
|
92
|
-
!filePathRelative.startsWith('./') &&
|
|
93
|
-
!filePathRelative.startsWith('../'));
|
|
94
|
-
const filePathAbsoluteUserRootDir = `/${filePathRelative}`;
|
|
95
|
-
(0, utils_js_1.assert)(filePathAbsoluteUserRootDir === getFilePathAbsoluteUserRootDir2(filePathAbsoluteFilesystem, userRootDir));
|
|
96
|
-
return filePathAbsoluteUserRootDir;
|
|
97
110
|
}
|
|
98
|
-
|
|
111
|
+
function getModuleFilePathAbsolute(moduleId, config) {
|
|
112
|
+
const { filePathAbsoluteUserRootDir, filePathAbsoluteFilesystem } = getModuleFilePath(moduleId, config);
|
|
113
|
+
return filePathAbsoluteUserRootDir || filePathAbsoluteFilesystem;
|
|
114
|
+
}
|
|
115
|
+
exports.getModuleFilePathAbsolute = getModuleFilePathAbsolute;
|
|
116
|
+
function getModuleFilePathRelative(moduleId, config) {
|
|
117
|
+
const { filePathRelativeUserRootDir } = getModuleFilePath(moduleId, config);
|
|
118
|
+
return filePathRelativeUserRootDir;
|
|
119
|
+
}
|
|
120
|
+
exports.getModuleFilePathRelative = getModuleFilePathRelative;
|
|
99
121
|
function getModuleFilePath(moduleId, config) {
|
|
100
122
|
const userRootDir = config.root;
|
|
101
|
-
(
|
|
123
|
+
assertModuleId(moduleId);
|
|
102
124
|
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
125
|
+
(0, utils_js_1.assertFilePathAbsoluteFilesystem)(userRootDir);
|
|
103
126
|
const filePathAbsoluteFilesystem = cleanModuleId(moduleId);
|
|
104
|
-
(0, utils_js_1.
|
|
105
|
-
const filePathAbsoluteUserRootDir =
|
|
106
|
-
|
|
127
|
+
(0, utils_js_1.assertFilePathAbsoluteFilesystem)(filePathAbsoluteFilesystem);
|
|
128
|
+
const { filePathAbsoluteUserRootDir, filePathRelativeUserRootDir } = getFilePathRelative({
|
|
129
|
+
filePathAbsoluteFilesystem,
|
|
130
|
+
userRootDir
|
|
131
|
+
});
|
|
132
|
+
return { filePathAbsoluteFilesystem, filePathAbsoluteUserRootDir, filePathRelativeUserRootDir };
|
|
133
|
+
}
|
|
134
|
+
function assertModuleId(moduleId) {
|
|
135
|
+
(0, utils_js_1.assertPosixPath)(moduleId);
|
|
136
|
+
(0, utils_js_1.assertFilePathAbsoluteFilesystem)(moduleId); // Can moduleId be something else than the filesystem absolute path?
|
|
107
137
|
}
|
|
108
|
-
exports.
|
|
138
|
+
exports.assertModuleId = assertModuleId;
|
|
109
139
|
function getFilePathToShowToUserFromUnkown(
|
|
110
140
|
// We don't have any guarentee about filePath, e.g. about whether is filePathAbsoluteFilesystem or filePathAbsoluteUserRootDir
|
|
111
141
|
filePathUnkown, userRootDir) {
|
|
112
142
|
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
113
|
-
(0, utils_js_1.
|
|
143
|
+
(0, utils_js_1.assertFilePathAbsoluteFilesystem)(userRootDir);
|
|
114
144
|
filePathUnkown = cleanFilePathUnkown(filePathUnkown);
|
|
115
145
|
if (!filePathUnkown.startsWith(userRootDir)) {
|
|
116
146
|
return filePathUnkown;
|
|
@@ -40,6 +40,6 @@ __exportStar(require("../../utils/injectRollupInputs.js"), exports);
|
|
|
40
40
|
__exportStar(require("../../utils/humanizeTime.js"), exports);
|
|
41
41
|
__exportStar(require("../../utils/pLimit.js"), exports);
|
|
42
42
|
__exportStar(require("../../utils/assertVersion.js"), exports);
|
|
43
|
-
__exportStar(require("../../utils/
|
|
43
|
+
__exportStar(require("../../utils/isFilePathAbsoluteFilesystem.js"), exports);
|
|
44
44
|
__exportStar(require("../../utils/isArray.js"), exports);
|
|
45
45
|
__exportStar(require("../../utils/PROJECT_VERSION.js"), exports);
|
|
@@ -105,7 +105,7 @@ async function runPrerender(options, manuallyTriggered) {
|
|
|
105
105
|
}
|
|
106
106
|
const { partial = false, noExtraDir = false, parallel = true } = prerenderConfig || {};
|
|
107
107
|
const concurrencyLimit = (0, utils_js_1.pLimit)(parallel === false || parallel === 0 ? 1 : parallel === true || parallel === undefined ? (0, os_1.cpus)().length : parallel);
|
|
108
|
-
(0, utils_js_1.
|
|
108
|
+
(0, utils_js_1.assertFilePathAbsoluteFilesystem)(outDirRoot); // Needed for loadImportBuild(outDir) of @brillout/vite-plugin-server-entry
|
|
109
109
|
await (0, globalContext_js_1.initGlobalContext)(true, outDirRoot);
|
|
110
110
|
const renderContext = await (0, renderPageAlreadyRouted_js_1.getRenderContext)();
|
|
111
111
|
renderContext.pageFilesAll.forEach(assertExportNames);
|
|
@@ -29,6 +29,6 @@ __exportStar(require("../../utils/urlToFile.js"), exports);
|
|
|
29
29
|
__exportStar(require("../../utils/isPlainObject.js"), exports);
|
|
30
30
|
__exportStar(require("../../utils/assertNodeEnv.js"), exports);
|
|
31
31
|
__exportStar(require("../../utils/pLimit.js"), exports);
|
|
32
|
-
__exportStar(require("../../utils/
|
|
32
|
+
__exportStar(require("../../utils/isFilePathAbsoluteFilesystem.js"), exports);
|
|
33
33
|
__exportStar(require("../../utils/isArray.js"), exports);
|
|
34
34
|
__exportStar(require("../../utils/changeEnumerable.js"), exports);
|
|
@@ -0,0 +1,60 @@
|
|
|
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.isFilePathAbsolute = exports.assertFilePathAbsoluteFilesystem = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const assert_js_1 = require("./assert.js");
|
|
9
|
+
const filesystemPathHandling_js_1 = require("./filesystemPathHandling.js");
|
|
10
|
+
/**
|
|
11
|
+
* Asserts that `filePath` is an absolute file path starting from the filesystem root.
|
|
12
|
+
*
|
|
13
|
+
* It isn't reliable for Linux users, but that's okay because the assertion will eventually fail on windows.
|
|
14
|
+
*/
|
|
15
|
+
function assertFilePathAbsoluteFilesystem(filePath) {
|
|
16
|
+
// The assert is "eventually reliable":
|
|
17
|
+
// - For Windows users, the assert is correct.
|
|
18
|
+
// - For Linux users assertFilePathAbsoluteFilesystem() will erroneously succeed if `p` is a path absolute from the user root dir.
|
|
19
|
+
// - But that's okay because the assertion will eventually fail for Windows users.
|
|
20
|
+
(0, assert_js_1.assert)(isFilePathAbsoluteFilesystem(filePath));
|
|
21
|
+
(0, filesystemPathHandling_js_1.assertPosixPath)(filePath);
|
|
22
|
+
}
|
|
23
|
+
exports.assertFilePathAbsoluteFilesystem = assertFilePathAbsoluteFilesystem;
|
|
24
|
+
/**
|
|
25
|
+
* Whether `filePath` is an absolute file path starting from the filesystem root.
|
|
26
|
+
*
|
|
27
|
+
* Isn't reliable for Linux users: it returns `true` for an absolute path starting from the user root dir.
|
|
28
|
+
*/
|
|
29
|
+
function isFilePathAbsoluteFilesystem(filePath) {
|
|
30
|
+
(0, assert_js_1.assert)(!filePath.startsWith('/@fs/'));
|
|
31
|
+
if (process.platform !== 'win32') {
|
|
32
|
+
// - For linux users, there doesn't seem to be a reliable way to distinguish between:
|
|
33
|
+
// - File path absolute starting from filesystem root, e.g. /home/rom/code/my-app/pages/about/+Page.js
|
|
34
|
+
// - File path absolute starting from user root dir (Vite's `config.root`), e.g. /pages/about/+Page.js
|
|
35
|
+
// - Checking whether `p` starts with the first directory of process.cwd() (or `userRootDir`) can be erroneous, most notably when using docker: https://github.com/vikejs/vike/issues/703
|
|
36
|
+
// - Using require.resolve() would be a solution but probably too slow?
|
|
37
|
+
return filePath.startsWith('/');
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
const yes = path_1.default.win32.isAbsolute(filePath);
|
|
41
|
+
// Ensure isFilePathAbsoluteFilesystem() returns `false` if path is absolute starting from the user root dir (see comments above).
|
|
42
|
+
if (yes)
|
|
43
|
+
(0, assert_js_1.assert)(!filePath.startsWith('/'));
|
|
44
|
+
return yes;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Whether `filePath` is an absolute file path.
|
|
49
|
+
*
|
|
50
|
+
* Returns `true` regardless whether it starts from the user root dir or filesystem root.
|
|
51
|
+
*/
|
|
52
|
+
function isFilePathAbsolute(filePath) {
|
|
53
|
+
(0, assert_js_1.assert)(!filePath.startsWith('/@fs/'));
|
|
54
|
+
// Absolute path starting from the user root dir.
|
|
55
|
+
if (filePath.startsWith('/'))
|
|
56
|
+
return true;
|
|
57
|
+
// Seems to be reliable: https://nodejs.org/api/path.html#pathisabsolutepath
|
|
58
|
+
return path_1.default.isAbsolute(filePath);
|
|
59
|
+
}
|
|
60
|
+
exports.isFilePathAbsolute = isFilePathAbsolute;
|
|
@@ -26,6 +26,7 @@ import pc from '@brillout/picocolors';
|
|
|
26
26
|
import { fileEnv } from './plugins/fileEnv.js';
|
|
27
27
|
import { setResolveClientEntriesDev } from '../runtime/renderPage/getPageAssets.js';
|
|
28
28
|
import { resolveClientEntriesDev } from './resolveClientEntriesDev.js';
|
|
29
|
+
import { workaroundCssModuleHmr } from './plugins/workaroundCssModuleHmr.js';
|
|
29
30
|
assertNodeEnv_onVikePluginLoad();
|
|
30
31
|
markEnvAsVikePluginLoaded();
|
|
31
32
|
assertViteVersion();
|
|
@@ -50,7 +51,8 @@ function plugin(vikeConfig) {
|
|
|
50
51
|
...importBuild(),
|
|
51
52
|
baseUrls(vikeConfig),
|
|
52
53
|
envVarsPlugin(),
|
|
53
|
-
fileEnv()
|
|
54
|
+
fileEnv(),
|
|
55
|
+
workaroundCssModuleHmr()
|
|
54
56
|
];
|
|
55
57
|
return plugins;
|
|
56
58
|
}
|
|
@@ -2,9 +2,11 @@ export { distFileNames };
|
|
|
2
2
|
// Attempt to preserve file structure of `.page.js` files:
|
|
3
3
|
// - https://github.com/vikejs/vike/commit/11a4c49e5403aa7c37c8020c462b499425b41854
|
|
4
4
|
// - Blocker: https://github.com/rollup/rollup/issues/4724
|
|
5
|
-
import { assertPosixPath, assert, assertUsage, isArray, isCallable } from '../utils.js';
|
|
5
|
+
import { assertPosixPath, assert, assertUsage, isArray, isCallable, isFilePathAbsolute } from '../utils.js';
|
|
6
6
|
import path from 'path';
|
|
7
|
+
import crypto from 'crypto';
|
|
7
8
|
import { getAssetsDir } from '../shared/getAssetsDir.js';
|
|
9
|
+
import { assertModuleId, getModuleFilePathAbsolute } from '../shared/getFilePath.js';
|
|
8
10
|
function distFileNames() {
|
|
9
11
|
return {
|
|
10
12
|
name: 'vike:distFileNames',
|
|
@@ -34,22 +36,61 @@ function distFileNames() {
|
|
|
34
36
|
{
|
|
35
37
|
const manualChunksOriginal = rollupOutput.manualChunks;
|
|
36
38
|
rollupOutput.manualChunks = function (id, ...args) {
|
|
37
|
-
if (id.endsWith('.css') && id.includes('node_modules'))
|
|
38
|
-
return 'vendor';
|
|
39
39
|
if (manualChunksOriginal) {
|
|
40
40
|
if (isCallable(manualChunksOriginal)) {
|
|
41
|
-
|
|
41
|
+
const result = manualChunksOriginal.call(this, id, ...args);
|
|
42
|
+
if (result !== undefined)
|
|
43
|
+
return result;
|
|
42
44
|
}
|
|
43
45
|
else {
|
|
44
46
|
assertUsage(false, "The Vite's configuration build.rollupOptions.output.manualChunks must be a function. Reach out if you need to set it to another value.");
|
|
45
47
|
}
|
|
46
48
|
}
|
|
49
|
+
// Disable CSS bundling to workaround https://github.com/vikejs/vike/issues/1815
|
|
50
|
+
if (id.endsWith('.css')) {
|
|
51
|
+
if (isFilePathAbsolute(id)) {
|
|
52
|
+
assertPosixPath(id);
|
|
53
|
+
assertModuleId(id);
|
|
54
|
+
let name;
|
|
55
|
+
const isNodeModules = id.match(/node_modules\/([^\/]+)\/(?!.*node_modules)/);
|
|
56
|
+
if (isNodeModules) {
|
|
57
|
+
name = isNodeModules[1];
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
const filePath = getModuleFilePathAbsolute(id, config);
|
|
61
|
+
name = filePath;
|
|
62
|
+
name = name.split('.').slice(0, -1).join('.'); // remove file extension
|
|
63
|
+
name = name.split('/').join('_');
|
|
64
|
+
}
|
|
65
|
+
// Make fileHash the same between local development and CI
|
|
66
|
+
const idStable = path.posix.relative(config.root, id);
|
|
67
|
+
// Don't remove `?` queries because each `id` should belong to a unique bundle.
|
|
68
|
+
const hash = getIdHash(idStable);
|
|
69
|
+
return `${name}-${hash}`;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
let name;
|
|
73
|
+
const isVirtualModule = id.match(/virtual:([^:]+):/);
|
|
74
|
+
if (!isVirtualModule) {
|
|
75
|
+
name = 'style';
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
name = isVirtualModule[1];
|
|
79
|
+
assert(name);
|
|
80
|
+
}
|
|
81
|
+
const hash = getIdHash(id);
|
|
82
|
+
return `${name}-${hash}`;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
47
85
|
};
|
|
48
86
|
}
|
|
49
87
|
});
|
|
50
88
|
}
|
|
51
89
|
};
|
|
52
90
|
}
|
|
91
|
+
function getIdHash(id) {
|
|
92
|
+
return crypto.createHash('md5').update(id).digest('hex').slice(0, 8);
|
|
93
|
+
}
|
|
53
94
|
function getAssetFileName(assetInfo, config) {
|
|
54
95
|
const assetsDir = getAssetsDir(config);
|
|
55
96
|
const dir = assetsDir + '/static';
|
|
@@ -2,7 +2,7 @@ export { envVarsPlugin };
|
|
|
2
2
|
import { loadEnv } from 'vite';
|
|
3
3
|
import { assert, assertPosixPath, assertUsage, assertWarning, escapeRegex, isArray, lowerFirst } from '../utils.js';
|
|
4
4
|
import { sourceMapPassthrough } from '../shared/rollupSourceMap.js';
|
|
5
|
-
import {
|
|
5
|
+
import { getModuleFilePathAbsolute } from '../shared/getFilePath.js';
|
|
6
6
|
// TODO/enventually: (after we implemented vike.config.js)
|
|
7
7
|
// - Make import.meta.env work inside +config.js
|
|
8
8
|
// - For it to work, we'll probably need the user to define the settings (e.g. `envDir`) for loadEnv() inside vike.config.js instead of vite.config.js
|
|
@@ -49,7 +49,7 @@ function envVarsPlugin() {
|
|
|
49
49
|
if (isPrivate && isClientSide) {
|
|
50
50
|
if (!envStatementRegEx.test(code))
|
|
51
51
|
return;
|
|
52
|
-
const modulePath =
|
|
52
|
+
const modulePath = getModuleFilePathAbsolute(id, config);
|
|
53
53
|
const errMsgAddendum = isBuild ? '' : ' (Vike will prevent your app from building for production)';
|
|
54
54
|
const keyPublic = `${PUBLIC_ENV_PREFIX}${envName}`;
|
|
55
55
|
const errMsg = `${envStatement} is used in client-side file ${modulePath} which means that the environment variable ${envName} will be included in client-side bundles and, therefore, ${envName} will be publicly exposed which can be a security leak${errMsgAddendum}. Use ${envStatement} only in server-side files, or rename ${envName} to ${keyPublic}, see https://vike.dev/env`;
|
|
@@ -3,7 +3,7 @@ import { assert, assertUsage, assertWarning, capitalizeFirstLetter } from '../ut
|
|
|
3
3
|
import { extractAssetsRE } from './extractAssetsPlugin.js';
|
|
4
4
|
import { extractExportNamesRE } from './extractExportNamesPlugin.js';
|
|
5
5
|
import pc from '@brillout/picocolors';
|
|
6
|
-
import {
|
|
6
|
+
import { getModuleFilePathAbsolute } from '../shared/getFilePath.js';
|
|
7
7
|
function fileEnv() {
|
|
8
8
|
let config;
|
|
9
9
|
let isDev = false;
|
|
@@ -62,7 +62,7 @@ function fileEnv() {
|
|
|
62
62
|
return;
|
|
63
63
|
// Show error message
|
|
64
64
|
let errMsg;
|
|
65
|
-
let modulePathPretty =
|
|
65
|
+
let modulePathPretty = getModuleFilePathAbsolute(moduleId, config);
|
|
66
66
|
modulePathPretty = modulePathPretty.replaceAll(suffix, pc.bold(suffix));
|
|
67
67
|
errMsg = `${capitalizeFirstLetter(envExpect)}-only file ${modulePathPretty} (https://vike.dev/file-env) imported on the ${envActual}-side`;
|
|
68
68
|
if (importer &&
|
|
@@ -70,7 +70,7 @@ function fileEnv() {
|
|
|
70
70
|
!importer.includes('virtual:vike:') &&
|
|
71
71
|
// I don't know why and who sets importer to '<stdin>' (I guess Vite?)
|
|
72
72
|
importer !== '<stdin>') {
|
|
73
|
-
const importerPath =
|
|
73
|
+
const importerPath = getModuleFilePathAbsolute(importer, config);
|
|
74
74
|
errMsg += ` by ${importerPath}`;
|
|
75
75
|
}
|
|
76
76
|
if (isDev) {
|
|
@@ -9,7 +9,7 @@ import { isVirtualFileIdImportUserCode } from '../../../shared/virtual-files/vir
|
|
|
9
9
|
import { vikeConfigDependencies, reloadVikeConfig, isVikeConfigFile } from './v1-design/getVikeConfig.js';
|
|
10
10
|
import pc from '@brillout/picocolors';
|
|
11
11
|
import { logConfigInfo, clearLogs } from '../../shared/loggerNotProd.js';
|
|
12
|
-
import {
|
|
12
|
+
import { getModuleFilePathAbsolute } from '../../shared/getFilePath.js';
|
|
13
13
|
function importUserCode() {
|
|
14
14
|
let config;
|
|
15
15
|
let configVike;
|
|
@@ -120,7 +120,7 @@ function isVikeConfigModule(filePathAbsoluteFilesystem) {
|
|
|
120
120
|
}
|
|
121
121
|
function reloadConfig(filePath, config, op) {
|
|
122
122
|
{
|
|
123
|
-
const filePathToShowToUserResolved =
|
|
123
|
+
const filePathToShowToUserResolved = getModuleFilePathAbsolute(filePath, config);
|
|
124
124
|
const msg = `${op} ${pc.dim(filePathToShowToUserResolved)}`;
|
|
125
125
|
logConfigInfo(msg, 'info');
|
|
126
126
|
}
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js
CHANGED
|
@@ -2,7 +2,7 @@ export { resolvePointerImportOfConfig };
|
|
|
2
2
|
export { resolvePointerImport };
|
|
3
3
|
export { clearFilesEnvMap };
|
|
4
4
|
import pc from '@brillout/picocolors';
|
|
5
|
-
import { assert, assertIsNpmPackageImport, assertPosixPath, assertUsage, deepEqual,
|
|
5
|
+
import { assert, assertIsNpmPackageImport, assertPosixPath, assertUsage, deepEqual, isFilePathAbsolute, requireResolve } from '../../../../utils.js';
|
|
6
6
|
import { parsePointerImportData } from './transformFileImports.js';
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import { getFilePathAbsoluteUserRootDir, getFilePathResolved, getFilePathUnresolved } from '../../../../shared/getFilePath.js';
|
|
@@ -33,7 +33,7 @@ function resolvePointerImport(pointerImportData, importerFilePath, userRootDir)
|
|
|
33
33
|
// - An npm package import
|
|
34
34
|
// - importPath cannot be a path alias (since esbuild resolves path aliases, see transpileAndExecuteFile.ts)
|
|
35
35
|
assertPosixPath(importPath);
|
|
36
|
-
if (importPath.startsWith('.') ||
|
|
36
|
+
if (importPath.startsWith('.') || isFilePathAbsolute(importPath)) {
|
|
37
37
|
if (importPath.startsWith('.')) {
|
|
38
38
|
assert(importPath.startsWith('./') || importPath.startsWith('../'));
|
|
39
39
|
}
|
|
@@ -7,7 +7,7 @@ import fs from 'fs';
|
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import pc from '@brillout/picocolors';
|
|
9
9
|
import { import_ } from '@brillout/import';
|
|
10
|
-
import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, assertWarning, isObject, toPosixPath, assertUsage, isJavaScriptFile, createDebugger,
|
|
10
|
+
import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, assertWarning, isObject, toPosixPath, assertUsage, isJavaScriptFile, createDebugger, assertFilePathAbsoluteFilesystem, assertIsNpmPackageImport } from '../../../../utils.js';
|
|
11
11
|
import { transformFileImports } from './transformFileImports.js';
|
|
12
12
|
import { vikeConfigDependencies } from '../getVikeConfig.js';
|
|
13
13
|
import 'source-map-support/register.js';
|
|
@@ -120,7 +120,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
120
120
|
// isNpmPackageImport(str, { cannotBePathAlias: true })
|
|
121
121
|
// assertIsNpmPackageImport()
|
|
122
122
|
// ```
|
|
123
|
-
|
|
123
|
+
assertFilePathAbsoluteFilesystem(importPathResolved);
|
|
124
124
|
// vike-{react,vue,solid} follow the convention that their config export resolves to a file named +config.js
|
|
125
125
|
// - This is temporary, see comment below.
|
|
126
126
|
const isVikeExtensionConfigImport = importPathResolved.endsWith('+config.js');
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { workaroundCssModuleHmr };
|
|
2
|
+
function workaroundCssModuleHmr() {
|
|
3
|
+
return {
|
|
4
|
+
name: 'vike:workaroundCssModuleHmr',
|
|
5
|
+
handleHotUpdate(ctx) {
|
|
6
|
+
// prevent full reload due to non self-accepting css module.
|
|
7
|
+
// here only "?direct" module should be filtered out as it doesn't have a parent module.
|
|
8
|
+
if (ctx.file.includes('module.css')) {
|
|
9
|
+
return ctx.modules.filter((m) => !m.id?.includes('?direct'));
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export { getFilePathResolved };
|
|
2
2
|
export { getFilePathUnresolved };
|
|
3
|
-
export {
|
|
3
|
+
export { getFilePathAbsoluteUserRootDir };
|
|
4
4
|
export { getFilePathToShowToUserFromUnkown };
|
|
5
|
+
export { getModuleFilePathAbsolute };
|
|
6
|
+
export { getModuleFilePathRelative };
|
|
5
7
|
export { cleanFilePathUnkown };
|
|
6
|
-
export {
|
|
8
|
+
export { assertModuleId };
|
|
7
9
|
import type { FilePathResolved, FilePathUnresolved } from '../../../shared/page-configs/FilePath.js';
|
|
8
10
|
import type { ResolvedConfig } from 'vite';
|
|
9
11
|
declare function getFilePathResolved(args: {
|
|
@@ -22,6 +24,8 @@ declare function getFilePathAbsoluteUserRootDir({ filePathAbsoluteFilesystem, us
|
|
|
22
24
|
filePathAbsoluteFilesystem: string;
|
|
23
25
|
userRootDir: string;
|
|
24
26
|
}): string | null;
|
|
25
|
-
declare function
|
|
27
|
+
declare function getModuleFilePathAbsolute(moduleId: string, config: ResolvedConfig): string;
|
|
28
|
+
declare function getModuleFilePathRelative(moduleId: string, config: ResolvedConfig): string;
|
|
29
|
+
declare function assertModuleId(moduleId: string): void;
|
|
26
30
|
declare function getFilePathToShowToUserFromUnkown(filePathUnkown: string, userRootDir: string): string;
|
|
27
31
|
declare function cleanFilePathUnkown(filePathUnknown: string): string;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
export { getFilePathResolved };
|
|
2
2
|
export { getFilePathUnresolved };
|
|
3
|
-
export {
|
|
3
|
+
export { getFilePathAbsoluteUserRootDir };
|
|
4
4
|
export { getFilePathToShowToUserFromUnkown };
|
|
5
|
+
export { getModuleFilePathAbsolute };
|
|
6
|
+
export { getModuleFilePathRelative };
|
|
5
7
|
export { cleanFilePathUnkown };
|
|
6
|
-
export {
|
|
8
|
+
export { assertModuleId };
|
|
7
9
|
import path from 'path';
|
|
8
|
-
import { assert, assertIsNpmPackageImport,
|
|
10
|
+
import { assert, assertIsNpmPackageImport, assertFilePathAbsoluteFilesystem, assertPosixPath, toPosixPath } from '../utils.js';
|
|
9
11
|
function getFilePathResolved(args) {
|
|
10
12
|
const { userRootDir } = args;
|
|
11
13
|
let filePathAbsoluteFilesystem;
|
|
@@ -19,7 +21,7 @@ function getFilePathResolved(args) {
|
|
|
19
21
|
filePathAbsoluteFilesystem = getFilePathAbsoluteUserFilesystem({ filePathAbsoluteUserRootDir, userRootDir });
|
|
20
22
|
}
|
|
21
23
|
assert(filePathAbsoluteFilesystem);
|
|
22
|
-
|
|
24
|
+
assertFilePathAbsoluteFilesystem(filePathAbsoluteFilesystem);
|
|
23
25
|
const filePathToShowToUserResolved = filePathAbsoluteUserRootDir || filePathAbsoluteFilesystem;
|
|
24
26
|
assert(filePathToShowToUserResolved);
|
|
25
27
|
assertPosixPath(filePathAbsoluteFilesystem);
|
|
@@ -68,45 +70,73 @@ function getFilePathUnresolved(args) {
|
|
|
68
70
|
function getFilePathAbsoluteUserFilesystem({ filePathAbsoluteUserRootDir, userRootDir }) {
|
|
69
71
|
assertPosixPath(filePathAbsoluteUserRootDir);
|
|
70
72
|
assertPosixPath(userRootDir);
|
|
71
|
-
|
|
73
|
+
assertFilePathAbsoluteFilesystem(userRootDir);
|
|
72
74
|
const filePathAbsoluteFilesystem = path.posix.join(userRootDir, filePathAbsoluteUserRootDir);
|
|
73
|
-
|
|
75
|
+
assertFilePathAbsoluteFilesystem(userRootDir);
|
|
74
76
|
return filePathAbsoluteFilesystem;
|
|
75
77
|
}
|
|
76
78
|
function getFilePathAbsoluteUserRootDir({ filePathAbsoluteFilesystem, userRootDir }) {
|
|
79
|
+
const { filePathAbsoluteUserRootDir } = getFilePathRelative({
|
|
80
|
+
filePathAbsoluteFilesystem,
|
|
81
|
+
userRootDir
|
|
82
|
+
});
|
|
83
|
+
return filePathAbsoluteUserRootDir;
|
|
84
|
+
}
|
|
85
|
+
function getFilePathRelative({ filePathAbsoluteFilesystem, userRootDir }) {
|
|
77
86
|
assertPosixPath(filePathAbsoluteFilesystem);
|
|
78
87
|
assertPosixPath(userRootDir);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const
|
|
88
|
+
assertFilePathAbsoluteFilesystem(filePathAbsoluteFilesystem);
|
|
89
|
+
assertFilePathAbsoluteFilesystem(userRootDir);
|
|
90
|
+
const filePathRelativeUserRootDir = path.posix.relative(userRootDir, filePathAbsoluteFilesystem);
|
|
82
91
|
if (!filePathAbsoluteFilesystem.startsWith(userRootDir)) {
|
|
83
|
-
assert(
|
|
84
|
-
return
|
|
92
|
+
assert(filePathRelativeUserRootDir.startsWith('../'));
|
|
93
|
+
return {
|
|
94
|
+
filePathAbsoluteUserRootDir: null,
|
|
95
|
+
filePathRelativeUserRootDir
|
|
96
|
+
};
|
|
85
97
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
98
|
+
else {
|
|
99
|
+
assert(!filePathRelativeUserRootDir.startsWith('/') &&
|
|
100
|
+
/* Not true if filePathRelative starts with a hidden directory (i.e. a directory with a name that starts with `.`)
|
|
101
|
+
!filePathRelative.startsWith('.') &&
|
|
102
|
+
*/
|
|
103
|
+
!filePathRelativeUserRootDir.startsWith('./') &&
|
|
104
|
+
!filePathRelativeUserRootDir.startsWith('../'));
|
|
105
|
+
const filePathAbsoluteUserRootDir = `/${filePathRelativeUserRootDir}`;
|
|
106
|
+
assert(filePathAbsoluteUserRootDir === getFilePathAbsoluteUserRootDir2(filePathAbsoluteFilesystem, userRootDir));
|
|
107
|
+
return { filePathAbsoluteUserRootDir, filePathRelativeUserRootDir };
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function getModuleFilePathAbsolute(moduleId, config) {
|
|
111
|
+
const { filePathAbsoluteUserRootDir, filePathAbsoluteFilesystem } = getModuleFilePath(moduleId, config);
|
|
112
|
+
return filePathAbsoluteUserRootDir || filePathAbsoluteFilesystem;
|
|
113
|
+
}
|
|
114
|
+
function getModuleFilePathRelative(moduleId, config) {
|
|
115
|
+
const { filePathRelativeUserRootDir } = getModuleFilePath(moduleId, config);
|
|
116
|
+
return filePathRelativeUserRootDir;
|
|
95
117
|
}
|
|
96
118
|
function getModuleFilePath(moduleId, config) {
|
|
97
119
|
const userRootDir = config.root;
|
|
98
|
-
|
|
120
|
+
assertModuleId(moduleId);
|
|
99
121
|
assertPosixPath(userRootDir);
|
|
122
|
+
assertFilePathAbsoluteFilesystem(userRootDir);
|
|
100
123
|
const filePathAbsoluteFilesystem = cleanModuleId(moduleId);
|
|
101
|
-
|
|
102
|
-
const filePathAbsoluteUserRootDir =
|
|
103
|
-
|
|
124
|
+
assertFilePathAbsoluteFilesystem(filePathAbsoluteFilesystem);
|
|
125
|
+
const { filePathAbsoluteUserRootDir, filePathRelativeUserRootDir } = getFilePathRelative({
|
|
126
|
+
filePathAbsoluteFilesystem,
|
|
127
|
+
userRootDir
|
|
128
|
+
});
|
|
129
|
+
return { filePathAbsoluteFilesystem, filePathAbsoluteUserRootDir, filePathRelativeUserRootDir };
|
|
130
|
+
}
|
|
131
|
+
function assertModuleId(moduleId) {
|
|
132
|
+
assertPosixPath(moduleId);
|
|
133
|
+
assertFilePathAbsoluteFilesystem(moduleId); // Can moduleId be something else than the filesystem absolute path?
|
|
104
134
|
}
|
|
105
135
|
function getFilePathToShowToUserFromUnkown(
|
|
106
136
|
// We don't have any guarentee about filePath, e.g. about whether is filePathAbsoluteFilesystem or filePathAbsoluteUserRootDir
|
|
107
137
|
filePathUnkown, userRootDir) {
|
|
108
138
|
assertPosixPath(userRootDir);
|
|
109
|
-
|
|
139
|
+
assertFilePathAbsoluteFilesystem(userRootDir);
|
|
110
140
|
filePathUnkown = cleanFilePathUnkown(filePathUnkown);
|
|
111
141
|
if (!filePathUnkown.startsWith(userRootDir)) {
|
|
112
142
|
return filePathUnkown;
|
|
@@ -18,6 +18,6 @@ export * from '../../utils/injectRollupInputs.js';
|
|
|
18
18
|
export * from '../../utils/humanizeTime.js';
|
|
19
19
|
export * from '../../utils/pLimit.js';
|
|
20
20
|
export * from '../../utils/assertVersion.js';
|
|
21
|
-
export * from '../../utils/
|
|
21
|
+
export * from '../../utils/isFilePathAbsoluteFilesystem.js';
|
|
22
22
|
export * from '../../utils/isArray.js';
|
|
23
23
|
export * from '../../utils/PROJECT_VERSION.js';
|
|
@@ -24,6 +24,6 @@ export * from '../../utils/injectRollupInputs.js';
|
|
|
24
24
|
export * from '../../utils/humanizeTime.js';
|
|
25
25
|
export * from '../../utils/pLimit.js';
|
|
26
26
|
export * from '../../utils/assertVersion.js';
|
|
27
|
-
export * from '../../utils/
|
|
27
|
+
export * from '../../utils/isFilePathAbsoluteFilesystem.js';
|
|
28
28
|
export * from '../../utils/isArray.js';
|
|
29
29
|
export * from '../../utils/PROJECT_VERSION.js';
|
|
@@ -5,7 +5,7 @@ export { runPrerender_forceExit };
|
|
|
5
5
|
import '../runtime/page-files/setup.js';
|
|
6
6
|
import path from 'path';
|
|
7
7
|
import { route } from '../../shared/route/index.js';
|
|
8
|
-
import { assert, assertUsage, assertWarning, hasProp, projectInfo, objectAssign, isObjectWithKeys, isCallable, getOutDirs, isPropertyGetter, assertPosixPath, urlToFile, isPlainObject, handleNodeEnv_prerender, pLimit,
|
|
8
|
+
import { assert, assertUsage, assertWarning, hasProp, projectInfo, objectAssign, isObjectWithKeys, isCallable, getOutDirs, isPropertyGetter, assertPosixPath, urlToFile, isPlainObject, handleNodeEnv_prerender, pLimit, assertFilePathAbsoluteFilesystem, isArray, changeEnumerable } from './utils.js';
|
|
9
9
|
import { prerenderPage, prerender404Page, getRenderContext, getPageContextInitEnhanced } from '../runtime/renderPage/renderPageAlreadyRouted.js';
|
|
10
10
|
import pc from '@brillout/picocolors';
|
|
11
11
|
import { cpus } from 'os';
|
|
@@ -77,7 +77,7 @@ async function runPrerender(options, manuallyTriggered) {
|
|
|
77
77
|
}
|
|
78
78
|
const { partial = false, noExtraDir = false, parallel = true } = prerenderConfig || {};
|
|
79
79
|
const concurrencyLimit = pLimit(parallel === false || parallel === 0 ? 1 : parallel === true || parallel === undefined ? cpus().length : parallel);
|
|
80
|
-
|
|
80
|
+
assertFilePathAbsoluteFilesystem(outDirRoot); // Needed for loadImportBuild(outDir) of @brillout/vite-plugin-server-entry
|
|
81
81
|
await initGlobalContext(true, outDirRoot);
|
|
82
82
|
const renderContext = await getRenderContext();
|
|
83
83
|
renderContext.pageFilesAll.forEach(assertExportNames);
|
|
@@ -11,6 +11,6 @@ export * from '../../utils/urlToFile.js';
|
|
|
11
11
|
export * from '../../utils/isPlainObject.js';
|
|
12
12
|
export * from '../../utils/assertNodeEnv.js';
|
|
13
13
|
export * from '../../utils/pLimit.js';
|
|
14
|
-
export * from '../../utils/
|
|
14
|
+
export * from '../../utils/isFilePathAbsoluteFilesystem.js';
|
|
15
15
|
export * from '../../utils/isArray.js';
|
|
16
16
|
export * from '../../utils/changeEnumerable.js';
|
|
@@ -13,6 +13,6 @@ export * from '../../utils/urlToFile.js';
|
|
|
13
13
|
export * from '../../utils/isPlainObject.js';
|
|
14
14
|
export * from '../../utils/assertNodeEnv.js';
|
|
15
15
|
export * from '../../utils/pLimit.js';
|
|
16
|
-
export * from '../../utils/
|
|
16
|
+
export * from '../../utils/isFilePathAbsoluteFilesystem.js';
|
|
17
17
|
export * from '../../utils/isArray.js';
|
|
18
18
|
export * from '../../utils/changeEnumerable.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.188-commit-373ae21";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.
|
|
2
|
+
export const PROJECT_VERSION = '0.4.188-commit-373ae21';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { assertFilePathAbsoluteFilesystem };
|
|
2
|
+
export { isFilePathAbsolute };
|
|
3
|
+
/**
|
|
4
|
+
* Asserts that `filePath` is an absolute file path starting from the filesystem root.
|
|
5
|
+
*
|
|
6
|
+
* It isn't reliable for Linux users, but that's okay because the assertion will eventually fail on windows.
|
|
7
|
+
*/
|
|
8
|
+
declare function assertFilePathAbsoluteFilesystem(filePath: string): void;
|
|
9
|
+
/**
|
|
10
|
+
* Whether `filePath` is an absolute file path.
|
|
11
|
+
*
|
|
12
|
+
* Returns `true` regardless whether it starts from the user root dir or filesystem root.
|
|
13
|
+
*/
|
|
14
|
+
declare function isFilePathAbsolute(filePath: string): boolean;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export { assertFilePathAbsoluteFilesystem };
|
|
2
|
+
export { isFilePathAbsolute };
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { assert } from './assert.js';
|
|
5
|
+
import { assertPosixPath } from './filesystemPathHandling.js';
|
|
6
|
+
/**
|
|
7
|
+
* Asserts that `filePath` is an absolute file path starting from the filesystem root.
|
|
8
|
+
*
|
|
9
|
+
* It isn't reliable for Linux users, but that's okay because the assertion will eventually fail on windows.
|
|
10
|
+
*/
|
|
11
|
+
function assertFilePathAbsoluteFilesystem(filePath) {
|
|
12
|
+
// The assert is "eventually reliable":
|
|
13
|
+
// - For Windows users, the assert is correct.
|
|
14
|
+
// - For Linux users assertFilePathAbsoluteFilesystem() will erroneously succeed if `p` is a path absolute from the user root dir.
|
|
15
|
+
// - But that's okay because the assertion will eventually fail for Windows users.
|
|
16
|
+
assert(isFilePathAbsoluteFilesystem(filePath));
|
|
17
|
+
assertPosixPath(filePath);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Whether `filePath` is an absolute file path starting from the filesystem root.
|
|
21
|
+
*
|
|
22
|
+
* Isn't reliable for Linux users: it returns `true` for an absolute path starting from the user root dir.
|
|
23
|
+
*/
|
|
24
|
+
function isFilePathAbsoluteFilesystem(filePath) {
|
|
25
|
+
assert(!filePath.startsWith('/@fs/'));
|
|
26
|
+
if (process.platform !== 'win32') {
|
|
27
|
+
// - For linux users, there doesn't seem to be a reliable way to distinguish between:
|
|
28
|
+
// - File path absolute starting from filesystem root, e.g. /home/rom/code/my-app/pages/about/+Page.js
|
|
29
|
+
// - File path absolute starting from user root dir (Vite's `config.root`), e.g. /pages/about/+Page.js
|
|
30
|
+
// - Checking whether `p` starts with the first directory of process.cwd() (or `userRootDir`) can be erroneous, most notably when using docker: https://github.com/vikejs/vike/issues/703
|
|
31
|
+
// - Using require.resolve() would be a solution but probably too slow?
|
|
32
|
+
return filePath.startsWith('/');
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
const yes = path.win32.isAbsolute(filePath);
|
|
36
|
+
// Ensure isFilePathAbsoluteFilesystem() returns `false` if path is absolute starting from the user root dir (see comments above).
|
|
37
|
+
if (yes)
|
|
38
|
+
assert(!filePath.startsWith('/'));
|
|
39
|
+
return yes;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Whether `filePath` is an absolute file path.
|
|
44
|
+
*
|
|
45
|
+
* Returns `true` regardless whether it starts from the user root dir or filesystem root.
|
|
46
|
+
*/
|
|
47
|
+
function isFilePathAbsolute(filePath) {
|
|
48
|
+
assert(!filePath.startsWith('/@fs/'));
|
|
49
|
+
// Absolute path starting from the user root dir.
|
|
50
|
+
if (filePath.startsWith('/'))
|
|
51
|
+
return true;
|
|
52
|
+
// Seems to be reliable: https://nodejs.org/api/path.html#pathisabsolutepath
|
|
53
|
+
return path.isAbsolute(filePath);
|
|
54
|
+
}
|
package/package.json
CHANGED
|
@@ -1,39 +0,0 @@
|
|
|
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.isPathFilesystemAbsolute = exports.assertPathFilesystemAbsolute = void 0;
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const assert_js_1 = require("./assert.js");
|
|
9
|
-
const filesystemPathHandling_js_1 = require("./filesystemPathHandling.js");
|
|
10
|
-
/** Assert path is absolute starting from the filesystem root. */
|
|
11
|
-
function assertPathFilesystemAbsolute(p) {
|
|
12
|
-
// The assert is "eventually reliable":
|
|
13
|
-
// - For Windows users, the assert is correct.
|
|
14
|
-
// - For Linux users assertPathFilesystemAbsolute() will erroneously succeed if `p` is a path absolute from the user root dir.
|
|
15
|
-
// - But that's okay because the assertion will eventually fail for Windows users.
|
|
16
|
-
(0, assert_js_1.assert)(isPathFilesystemAbsolute(p));
|
|
17
|
-
}
|
|
18
|
-
exports.assertPathFilesystemAbsolute = assertPathFilesystemAbsolute;
|
|
19
|
-
/** Whether path is absolute starting from the filesystem root. Isn't reliable for Linux users: isPathFilesystemAbsolute() returns `true` for paths absolute from the user root dir. */
|
|
20
|
-
function isPathFilesystemAbsolute(p) {
|
|
21
|
-
(0, filesystemPathHandling_js_1.assertPosixPath)(p);
|
|
22
|
-
(0, assert_js_1.assert)(!p.startsWith('/@fs/'));
|
|
23
|
-
if (process.platform !== 'win32') {
|
|
24
|
-
// - For linux users, there doesn't seem to be a reliable way to distinguish between:
|
|
25
|
-
// - File path absolute starting from filesystem root, e.g. /home/rom/code/my-app/pages/about/+Page.js
|
|
26
|
-
// - File path absolute starting from user root dir (Vite's `config.root`), e.g. /pages/about/+Page.js
|
|
27
|
-
// - Checking whether `p` starts with the first directory of process.cwd() (or `userRootDir`) can be erroneous, most notably when using docker: https://github.com/vikejs/vike/issues/703
|
|
28
|
-
// - Using require.resolve() would be a solution but probably too slow?
|
|
29
|
-
return p.startsWith('/');
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
const yes = path_1.default.win32.isAbsolute(p);
|
|
33
|
-
// Ensure isPathFilesystemAbsolute() returns `false` if path is absolute starting from the user root dir (see comments above).
|
|
34
|
-
if (yes)
|
|
35
|
-
(0, assert_js_1.assert)(!p.startsWith('/'));
|
|
36
|
-
return yes;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
exports.isPathFilesystemAbsolute = isPathFilesystemAbsolute;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { assertPathFilesystemAbsolute };
|
|
2
|
-
export { isPathFilesystemAbsolute };
|
|
3
|
-
/** Assert path is absolute starting from the filesystem root. */
|
|
4
|
-
declare function assertPathFilesystemAbsolute(p: string): void;
|
|
5
|
-
/** Whether path is absolute starting from the filesystem root. Isn't reliable for Linux users: isPathFilesystemAbsolute() returns `true` for paths absolute from the user root dir. */
|
|
6
|
-
declare function isPathFilesystemAbsolute(p: string): boolean;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
export { assertPathFilesystemAbsolute };
|
|
2
|
-
export { isPathFilesystemAbsolute };
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { assert } from './assert.js';
|
|
5
|
-
import { assertPosixPath } from './filesystemPathHandling.js';
|
|
6
|
-
/** Assert path is absolute starting from the filesystem root. */
|
|
7
|
-
function assertPathFilesystemAbsolute(p) {
|
|
8
|
-
// The assert is "eventually reliable":
|
|
9
|
-
// - For Windows users, the assert is correct.
|
|
10
|
-
// - For Linux users assertPathFilesystemAbsolute() will erroneously succeed if `p` is a path absolute from the user root dir.
|
|
11
|
-
// - But that's okay because the assertion will eventually fail for Windows users.
|
|
12
|
-
assert(isPathFilesystemAbsolute(p));
|
|
13
|
-
}
|
|
14
|
-
/** Whether path is absolute starting from the filesystem root. Isn't reliable for Linux users: isPathFilesystemAbsolute() returns `true` for paths absolute from the user root dir. */
|
|
15
|
-
function isPathFilesystemAbsolute(p) {
|
|
16
|
-
assertPosixPath(p);
|
|
17
|
-
assert(!p.startsWith('/@fs/'));
|
|
18
|
-
if (process.platform !== 'win32') {
|
|
19
|
-
// - For linux users, there doesn't seem to be a reliable way to distinguish between:
|
|
20
|
-
// - File path absolute starting from filesystem root, e.g. /home/rom/code/my-app/pages/about/+Page.js
|
|
21
|
-
// - File path absolute starting from user root dir (Vite's `config.root`), e.g. /pages/about/+Page.js
|
|
22
|
-
// - Checking whether `p` starts with the first directory of process.cwd() (or `userRootDir`) can be erroneous, most notably when using docker: https://github.com/vikejs/vike/issues/703
|
|
23
|
-
// - Using require.resolve() would be a solution but probably too slow?
|
|
24
|
-
return p.startsWith('/');
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
const yes = path.win32.isAbsolute(p);
|
|
28
|
-
// Ensure isPathFilesystemAbsolute() returns `false` if path is absolute starting from the user root dir (see comments above).
|
|
29
|
-
if (yes)
|
|
30
|
-
assert(!p.startsWith('/'));
|
|
31
|
-
return yes;
|
|
32
|
-
}
|
|
33
|
-
}
|