vike 0.4.167-commit-cfadd0a → 0.4.168-commit-ce94f5c
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/plugins/extractAssetsPlugin.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +7 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +0 -8
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +14 -35
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +112 -96
- package/dist/cjs/node/plugin/shared/getFilePath.js +6 -1
- package/dist/cjs/utils/assertPathIsFilesystemAbsolute.js +3 -3
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +7 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +1 -9
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +14 -35
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformFileImports.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +113 -97
- package/dist/esm/node/plugin/shared/getFilePath.js +6 -1
- package/dist/esm/utils/assertPathIsFilesystemAbsolute.js +3 -3
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +2 -2
|
@@ -189,7 +189,7 @@ function analyzeImport(importStatement) {
|
|
|
189
189
|
if (rawRE.test(moduleName)) {
|
|
190
190
|
return { moduleName, skip: true };
|
|
191
191
|
}
|
|
192
|
-
/* We
|
|
192
|
+
/* We shouldn't do this because of aliased imports
|
|
193
193
|
if (!moduleName.startsWith('.')) {
|
|
194
194
|
return { moduleName, skip: true }
|
|
195
195
|
}
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js
CHANGED
|
@@ -23,7 +23,13 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
|
|
|
23
23
|
// config.outDir is outside of config.root => it's going to be ignored anyways
|
|
24
24
|
outDirRelativeFromUserRootDir = null;
|
|
25
25
|
}
|
|
26
|
-
(0, utils_js_1.assert)(outDirRelativeFromUserRootDir === null ||
|
|
26
|
+
(0, utils_js_1.assert)(outDirRelativeFromUserRootDir === null ||
|
|
27
|
+
/* Not true if outDirRelativeFromUserRootDir starts with a hidden directory (i.e. a directory with a name that starts with `.`)
|
|
28
|
+
!outDirRelativeFromUserRootDir.startsWith('.') &&
|
|
29
|
+
*/
|
|
30
|
+
(!outDirRelativeFromUserRootDir.startsWith('./') &&
|
|
31
|
+
//
|
|
32
|
+
!outDirRelativeFromUserRootDir.startsWith('../')));
|
|
27
33
|
const timeBefore = new Date().getTime();
|
|
28
34
|
let files = [];
|
|
29
35
|
const res = await gitLsFiles(userRootDir, outDirRelativeFromUserRootDir);
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js
CHANGED
|
@@ -68,7 +68,6 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
|
|
|
68
68
|
const { importPath: importPathAbsolute } = importData;
|
|
69
69
|
const filePathAbsoluteFilesystem = (0, resolveImportPath_js_1.resolveImportPath)(importData, configFilePath);
|
|
70
70
|
(0, resolveImportPath_js_1.assertImportPath)(filePathAbsoluteFilesystem, importData, configFilePath);
|
|
71
|
-
warnUserLandExtension(importPathAbsolute, configFilePath);
|
|
72
71
|
const filePath = (0, getFilePath_js_1.getFilePathResolved)({ filePathAbsoluteFilesystem, userRootDir, importPathAbsolute });
|
|
73
72
|
extendsConfigFiles.push(filePath);
|
|
74
73
|
});
|
|
@@ -81,13 +80,6 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
|
|
|
81
80
|
const extendsFilePaths = extendsConfigFiles.map((f) => f.filePathAbsoluteFilesystem);
|
|
82
81
|
return { extendsConfigs, extendsFilePaths };
|
|
83
82
|
}
|
|
84
|
-
function warnUserLandExtension(importPath, configFilePath) {
|
|
85
|
-
// We preserve this feature because we may need it for eject
|
|
86
|
-
(0, utils_js_1.assertWarning)((0, utils_js_1.isNpmPackageImport)(importPath, {
|
|
87
|
-
// Vike config files don't support path aliases. (If they do one day, then Vike will/should be able to resolve path aliases.)
|
|
88
|
-
cannotBePathAlias: true
|
|
89
|
-
}) || importPath.includes('/node_modules/'), `${configFilePath.filePathToShowToUser} uses ${picocolors_1.default.cyan('extends')} to inherit from ${picocolors_1.default.cyan(importPath)} which is a user-land file: this is experimental and may be remove at any time. Reach out to a maintainer if you need this.`, { onlyOnce: true });
|
|
90
|
-
}
|
|
91
83
|
function getExtendsImportData(configFileExports, configFilePath) {
|
|
92
84
|
const { filePathToShowToUser } = configFilePath;
|
|
93
85
|
const configFileExport = (0, getConfigFileExport_js_1.getConfigFileExport)(configFileExports, filePathToShowToUser);
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js
CHANGED
|
@@ -22,13 +22,22 @@ function resolveImport(configValue, importerFilePath, userRootDir, configEnv, co
|
|
|
22
22
|
const fileExportPathToShowToUser = exportName === 'default' || exportName === configName ? [] : [exportName];
|
|
23
23
|
let filePath;
|
|
24
24
|
if (importPath.startsWith('.')) {
|
|
25
|
-
|
|
25
|
+
(0, utils_js_1.assert)(importPath.startsWith('./') || importPath.startsWith('../'));
|
|
26
|
+
assertImportPath(filePathAbsoluteFilesystem, importData, importerFilePath);
|
|
27
|
+
filePath = (0, getFilePath_js_1.getFilePathResolved)({ filePathAbsoluteFilesystem, userRootDir });
|
|
28
|
+
// Imports are included in virtual files, thus the relative path of imports need to resolved.
|
|
26
29
|
// ```
|
|
27
30
|
// [vite] Internal server error: Failed to resolve import "./onPageTransitionHooks" from "virtual:vike:pageConfigValuesAll:client:/pages/index". Does the file exist?
|
|
28
31
|
// ```
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
(0, utils_js_1.assertUsage)(filePath.filePathAbsoluteUserRootDir, `${importerFilePath.filePathToShowToUser} imports a relative path ${picocolors_1.default.cyan(importPath)} resolving outside of ${userRootDir} which is forbidden: import from a relative path inside ${userRootDir}, or import from a dependency's package.json#exports entry instead`);
|
|
33
|
+
// Alternativey, we can try one of the following but last time we tried none of the following worked.
|
|
34
|
+
// /*
|
|
35
|
+
// assert(filePathAbsoluteFilesystem.startsWith('/'))
|
|
36
|
+
// filePath = `/@fs${filePathAbsoluteFilesystem}`
|
|
37
|
+
// /*/
|
|
38
|
+
// assert(filePathAbsoluteUserRootDir.startsWith('../'))
|
|
39
|
+
// filePathAbsoluteUserRootDir = '/' + filePathAbsoluteUserRootDir
|
|
40
|
+
// //*/
|
|
32
41
|
}
|
|
33
42
|
else {
|
|
34
43
|
// importPath can be:
|
|
@@ -54,28 +63,6 @@ function resolveImport(configValue, importerFilePath, userRootDir, configEnv, co
|
|
|
54
63
|
};
|
|
55
64
|
}
|
|
56
65
|
exports.resolveImport = resolveImport;
|
|
57
|
-
function resolveImportPath_absoluteUserRootDir(filePathAbsoluteFilesystem, importData, configFilePath, userRootDir) {
|
|
58
|
-
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
59
|
-
let filePathAbsoluteUserRootDir;
|
|
60
|
-
if (filePathAbsoluteFilesystem.startsWith(userRootDir)) {
|
|
61
|
-
filePathAbsoluteUserRootDir = getVitePathFromAbsolutePath(filePathAbsoluteFilesystem, userRootDir);
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
(0, utils_js_1.assertUsage)(false, `${configFilePath.filePathToShowToUser} imports from a relative path ${picocolors_1.default.cyan(importData.importPath)} outside of ${userRootDir} which is forbidden: import from a relative path inside ${userRootDir}, or import from a dependency's package.json#exports entry instead`);
|
|
65
|
-
// None of the following works. Seems to be a Vite bug?
|
|
66
|
-
// /*
|
|
67
|
-
// assert(filePathAbsoluteFilesystem.startsWith('/'))
|
|
68
|
-
// filePath = `/@fs${filePathAbsoluteFilesystem}`
|
|
69
|
-
// /*/
|
|
70
|
-
// filePathAbsoluteUserRootDir = path.posix.relative(userRootDir, filePathAbsoluteFilesystem)
|
|
71
|
-
// assert(filePathAbsoluteUserRootDir.startsWith('../'))
|
|
72
|
-
// filePathAbsoluteUserRootDir = '/' + filePathAbsoluteUserRootDir
|
|
73
|
-
// //*/
|
|
74
|
-
}
|
|
75
|
-
(0, utils_js_1.assertPosixPath)(filePathAbsoluteUserRootDir);
|
|
76
|
-
(0, utils_js_1.assert)(filePathAbsoluteUserRootDir.startsWith('/'));
|
|
77
|
-
return filePathAbsoluteUserRootDir;
|
|
78
|
-
}
|
|
79
66
|
function resolveImportPath(importData, importerFilePath) {
|
|
80
67
|
const importerFilePathAbsolute = importerFilePath.filePathAbsoluteFilesystem;
|
|
81
68
|
(0, utils_js_1.assertPosixPath)(importerFilePathAbsolute);
|
|
@@ -97,6 +84,7 @@ function assertImportPath(filePathAbsoluteFilesystem, importData, importerFilePa
|
|
|
97
84
|
: `The import ${picocolors_1.default.cyan(importString)} defined in ${filePathToShowToUser}`;
|
|
98
85
|
const errIntro2 = `${errIntro} couldn't be resolved: does ${importPathString}`;
|
|
99
86
|
if (importPath.startsWith('.')) {
|
|
87
|
+
(0, utils_js_1.assert)(importPath.startsWith('./') || importPath.startsWith('../'));
|
|
100
88
|
(0, utils_js_1.assertUsage)(false, `${errIntro2} point to an existing file?`);
|
|
101
89
|
}
|
|
102
90
|
else {
|
|
@@ -125,12 +113,3 @@ function clearFilesEnvMap() {
|
|
|
125
113
|
filesEnvMap.clear();
|
|
126
114
|
}
|
|
127
115
|
exports.clearFilesEnvMap = clearFilesEnvMap;
|
|
128
|
-
function getVitePathFromAbsolutePath(filePathAbsoluteFilesystem, root) {
|
|
129
|
-
(0, utils_js_1.assertPosixPath)(filePathAbsoluteFilesystem);
|
|
130
|
-
(0, utils_js_1.assertPosixPath)(root);
|
|
131
|
-
(0, utils_js_1.assert)(filePathAbsoluteFilesystem.startsWith(root));
|
|
132
|
-
let vitePath = path_1.default.posix.relative(root, filePathAbsoluteFilesystem);
|
|
133
|
-
(0, utils_js_1.assert)(!vitePath.startsWith('/') && !vitePath.startsWith('.'));
|
|
134
|
-
vitePath = '/' + vitePath;
|
|
135
|
-
return vitePath;
|
|
136
|
-
}
|
|
@@ -82,98 +82,96 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
82
82
|
// Esbuild still sometimes removes unused imports because of TypeScript: https://github.com/evanw/esbuild/issues/3034
|
|
83
83
|
treeShaking: false,
|
|
84
84
|
minify: false,
|
|
85
|
-
metafile:
|
|
86
|
-
bundle:
|
|
85
|
+
metafile: true,
|
|
86
|
+
bundle: true
|
|
87
87
|
};
|
|
88
|
-
let pointerImports;
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
setup(build) {
|
|
102
|
-
// https://github.com/evanw/esbuild/issues/3095#issuecomment-1546916366
|
|
88
|
+
let pointerImports = {};
|
|
89
|
+
options.plugins = [
|
|
90
|
+
// Determine whether an import should be:
|
|
91
|
+
// - A pointer import
|
|
92
|
+
// - Externalized
|
|
93
|
+
{
|
|
94
|
+
name: 'vike-esbuild',
|
|
95
|
+
setup(build) {
|
|
96
|
+
// https://github.com/brillout/esbuild-playground
|
|
97
|
+
build.onResolve({ filter: /.*/ }, async (args) => {
|
|
98
|
+
if (args.kind !== 'import-statement')
|
|
99
|
+
return;
|
|
100
|
+
// Avoid infinite loop: https://github.com/evanw/esbuild/issues/3095#issuecomment-1546916366
|
|
103
101
|
const useEsbuildResolver = 'useEsbuildResolver';
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
// - This is temporary, see comment below.
|
|
125
|
-
const isVikeExtensionConfigImport = resolved.path.endsWith('+config.js');
|
|
126
|
-
const isPointerImport =
|
|
102
|
+
if (args.pluginData?.[useEsbuildResolver])
|
|
103
|
+
return;
|
|
104
|
+
const { path, ...opts } = args;
|
|
105
|
+
opts.pluginData = { [useEsbuildResolver]: true };
|
|
106
|
+
const resolved = await build.resolve(path, opts);
|
|
107
|
+
if (resolved.errors.length > 0) {
|
|
108
|
+
/* We could do the following to let Node.js throw the error, but we don't because the error shown by esbuild is prettier: the Node.js error refers to the transpiled [build-f7i251e0iwnw]+config.ts.mjs file which isn't that nice, whereas esbuild refers to the source +config.ts file.
|
|
109
|
+
pointerImports[args.path] = false
|
|
110
|
+
return { external: true }
|
|
111
|
+
*/
|
|
112
|
+
// Let esbuild throw the error. (It throws a nice & pretty error.)
|
|
113
|
+
cleanEsbuildErrors(resolved.errors);
|
|
114
|
+
return resolved;
|
|
115
|
+
}
|
|
116
|
+
(0, utils_js_1.assert)(resolved.path);
|
|
117
|
+
resolved.path = (0, utils_js_1.toPosixPath)(resolved.path);
|
|
118
|
+
// vike-{react,vue,solid} follow the convention that their config export resolves to a file named +config.js
|
|
119
|
+
// - This is temporary, see comment below.
|
|
120
|
+
const isVikeExtensionConfigImport = resolved.path.endsWith('+config.js');
|
|
121
|
+
const isPointerImport = transformImports === 'all' ||
|
|
127
122
|
// .jsx, .vue, .svg, ... => obviously not config code
|
|
128
123
|
!(0, utils_js_1.isJavaScriptFile)(resolved.path) ||
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
name: 'vike:dependency-tracker',
|
|
156
|
-
setup(b) {
|
|
157
|
-
b.onLoad({ filter: /./ }, (args) => {
|
|
158
|
-
// We collect the dependency `args.path` in case the bulid fails (upon build error => error is thrown => no metafile)
|
|
159
|
-
let { path } = args;
|
|
160
|
-
path = (0, utils_js_1.toPosixPath)(path);
|
|
161
|
-
getVikeConfig_js_1.vikeConfigDependencies.add(path);
|
|
162
|
-
return undefined;
|
|
163
|
-
});
|
|
164
|
-
/* To exhaustively collect all dependencies upon build failure, we would also need to use onResolve().
|
|
165
|
-
* - Because onLoad() isn't call if the config dependency can't be resolved.
|
|
166
|
-
* - For example, the following breaks auto-reload (the config is stuck in its error state and the user needs to touch the importer for the config to reload):
|
|
167
|
-
* ```bash
|
|
168
|
-
* mv ./some-config-dependency.js /tmp/ && mv /tmp/some-config-dependency.js .
|
|
169
|
-
* ```
|
|
170
|
-
* - But implementing a fix is complex and isn't worth it.
|
|
171
|
-
b.onResolve(...)
|
|
172
|
-
*/
|
|
173
|
-
}
|
|
124
|
+
// Import of a Vike extension config => make it a pointer import because we want to show nice error messages (that can display whether a configas been set by the user or by a Vike extension).
|
|
125
|
+
// - We should have Node.js directly load vike-{react,vue,solid} while enforcing Vike extensions to set 'name' in their +config.js file.
|
|
126
|
+
// - vike@0.4.162 already started soft-requiring Vike extensions to set the name config
|
|
127
|
+
isVikeExtensionConfigImport ||
|
|
128
|
+
// Cannot be resolved by esbuild => take a leap of faith and make it a pointer import.
|
|
129
|
+
// - For example if esbuild cannot resolve a path alias while Vite can.
|
|
130
|
+
// - When tsconfig.js#compilerOptions.paths is set, then esbuild is able to resolve the path alias.
|
|
131
|
+
resolved.errors.length > 0;
|
|
132
|
+
pointerImports[resolved.path] = isPointerImport;
|
|
133
|
+
(0, utils_js_1.assertPosixPath)(resolved.path);
|
|
134
|
+
const isExternal = isPointerImport ||
|
|
135
|
+
// Performance: npm package imports that aren't pointer imports can be externalized. For example, if Vike eventually adds support for setting Vite configs in the vike.config.js file, then the user may import a Vite plugin in his vike.config.js file. (We could as well let esbuild always transpile /node_modules/ code but it would be useless and would unnecessarily slow down transpilation.)
|
|
136
|
+
resolved.path.includes('/node_modules/');
|
|
137
|
+
if (debug.isActivated)
|
|
138
|
+
debug('onResolved()', { args, resolved, isPointerImport, isExternal });
|
|
139
|
+
// We need esbuild to resolve path aliases so that we can use:
|
|
140
|
+
// isNpmPackageImport(str, { cannotBePathAlias: true })
|
|
141
|
+
// assertIsNpmPackageImport()
|
|
142
|
+
(0, utils_js_1.assertPathIsFilesystemAbsolute)(resolved.path);
|
|
143
|
+
if (isExternal) {
|
|
144
|
+
return { external: true, path: resolved.path };
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
return resolved;
|
|
148
|
+
}
|
|
149
|
+
});
|
|
174
150
|
}
|
|
175
|
-
|
|
176
|
-
|
|
151
|
+
},
|
|
152
|
+
// Track dependencies
|
|
153
|
+
{
|
|
154
|
+
name: 'vike:dependency-tracker',
|
|
155
|
+
setup(b) {
|
|
156
|
+
b.onLoad({ filter: /./ }, (args) => {
|
|
157
|
+
// We collect the dependency `args.path` in case the bulid fails (upon build error => error is thrown => no metafile)
|
|
158
|
+
let { path } = args;
|
|
159
|
+
path = (0, utils_js_1.toPosixPath)(path);
|
|
160
|
+
getVikeConfig_js_1.vikeConfigDependencies.add(path);
|
|
161
|
+
return undefined;
|
|
162
|
+
});
|
|
163
|
+
/* To exhaustively collect all dependencies upon build failure, we would also need to use onResolve().
|
|
164
|
+
* - Because onLoad() isn't call if the config dependency can't be resolved.
|
|
165
|
+
* - For example, the following breaks auto-reload (the config is stuck in its error state and the user needs to touch the importer for the config to reload):
|
|
166
|
+
* ```bash
|
|
167
|
+
* mv ./some-config-dependency.js /tmp/ && mv /tmp/some-config-dependency.js .
|
|
168
|
+
* ```
|
|
169
|
+
* - But implementing a fix is complex and isn't worth it.
|
|
170
|
+
b.onResolve(...)
|
|
171
|
+
*/
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
];
|
|
177
175
|
let result;
|
|
178
176
|
try {
|
|
179
177
|
result = await (0, esbuild_1.build)(options);
|
|
@@ -183,15 +181,13 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
183
181
|
throw err;
|
|
184
182
|
}
|
|
185
183
|
// Track dependencies
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
});
|
|
194
|
-
}
|
|
184
|
+
(0, utils_js_1.assert)(result.metafile);
|
|
185
|
+
Object.keys(result.metafile.inputs).forEach((filePathRelative) => {
|
|
186
|
+
filePathRelative = (0, utils_js_1.toPosixPath)(filePathRelative);
|
|
187
|
+
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
188
|
+
const filePathAbsoluteFilesystem = path_1.default.posix.join(userRootDir, filePathRelative);
|
|
189
|
+
getVikeConfig_js_1.vikeConfigDependencies.add(filePathAbsoluteFilesystem);
|
|
190
|
+
});
|
|
195
191
|
const code = result.outputFiles[0].text;
|
|
196
192
|
(0, utils_js_1.assert)(typeof code === 'string');
|
|
197
193
|
return { code, pointerImports };
|
|
@@ -316,3 +312,23 @@ function getErrIntroMsg(operation, filePath) {
|
|
|
316
312
|
].join(' ');
|
|
317
313
|
return msg;
|
|
318
314
|
}
|
|
315
|
+
function cleanEsbuildErrors(errors) {
|
|
316
|
+
errors.forEach((e) => (e.notes = e.notes.filter((note) =>
|
|
317
|
+
// Remove note:
|
|
318
|
+
// ```shell
|
|
319
|
+
// You can mark the path "#root/renderer/onRenderHtml_typo" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle.
|
|
320
|
+
// ```
|
|
321
|
+
//
|
|
322
|
+
// From error:
|
|
323
|
+
// ```shell
|
|
324
|
+
// ✘ [ERROR] Could not resolve "#root/renderer/onRenderHtml_typo" [plugin vike-esbuild]
|
|
325
|
+
//
|
|
326
|
+
// renderer/+config.h.js:1:29:
|
|
327
|
+
// 1 │ import { onRenderHtml } from "#root/renderer/onRenderHtml_typo"
|
|
328
|
+
// ╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
329
|
+
//
|
|
330
|
+
// You can mark the path "#root/renderer/onRenderHtml_typo" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle.
|
|
331
|
+
//
|
|
332
|
+
// ```
|
|
333
|
+
!note.text.includes('as external to exclude it from the bundle'))));
|
|
334
|
+
}
|
|
@@ -90,7 +90,12 @@ function getFilePathAbsoluteUserRootDir({ filePathAbsoluteFilesystem, userRootDi
|
|
|
90
90
|
(0, utils_js_1.assert)(filePathRelative.startsWith('../'));
|
|
91
91
|
return null;
|
|
92
92
|
}
|
|
93
|
-
(0, utils_js_1.assert)(!filePathRelative.startsWith('
|
|
93
|
+
(0, utils_js_1.assert)(!filePathRelative.startsWith('/') &&
|
|
94
|
+
/* Not true if filePathRelative starts with a hidden directory (i.e. a directory with a name that starts with `.`)
|
|
95
|
+
!filePathRelative.startsWith('.') &&
|
|
96
|
+
*/
|
|
97
|
+
!filePathRelative.startsWith('./') &&
|
|
98
|
+
!filePathRelative.startsWith('../'));
|
|
94
99
|
const filePathAbsoluteUserRootDir = `/${filePathRelative}`;
|
|
95
100
|
(0, utils_js_1.assert)(filePathAbsoluteUserRootDir === getFilePathAbsoluteUserRootDir2(filePathAbsoluteFilesystem, userRootDir));
|
|
96
101
|
return filePathAbsoluteUserRootDir;
|
|
@@ -11,11 +11,11 @@ const filesystemPathHandling_js_1 = require("./filesystemPathHandling.js");
|
|
|
11
11
|
function assertPathIsFilesystemAbsolute(p) {
|
|
12
12
|
(0, filesystemPathHandling_js_1.assertPosixPath)(p);
|
|
13
13
|
(0, assert_js_1.assert)(!p.startsWith('/@fs/'));
|
|
14
|
-
if (process.platform
|
|
15
|
-
(0, assert_js_1.assert)(
|
|
14
|
+
if (process.platform !== 'win32') {
|
|
15
|
+
(0, assert_js_1.assert)(p.startsWith('/'));
|
|
16
16
|
}
|
|
17
17
|
else {
|
|
18
|
-
(0, assert_js_1.assert)(
|
|
18
|
+
(0, assert_js_1.assert)(path_1.default.win32.isAbsolute(p));
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
exports.assertPathIsFilesystemAbsolute = assertPathIsFilesystemAbsolute;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PROJECT_VERSION = exports.projectInfo = void 0;
|
|
4
|
-
const PROJECT_VERSION = '0.4.
|
|
4
|
+
const PROJECT_VERSION = '0.4.168-commit-ce94f5c';
|
|
5
5
|
exports.PROJECT_VERSION = PROJECT_VERSION;
|
|
6
6
|
const projectInfo = {
|
|
7
7
|
projectName: 'Vike',
|
|
@@ -187,7 +187,7 @@ function analyzeImport(importStatement) {
|
|
|
187
187
|
if (rawRE.test(moduleName)) {
|
|
188
188
|
return { moduleName, skip: true };
|
|
189
189
|
}
|
|
190
|
-
/* We
|
|
190
|
+
/* We shouldn't do this because of aliased imports
|
|
191
191
|
if (!moduleName.startsWith('.')) {
|
|
192
192
|
return { moduleName, skip: true }
|
|
193
193
|
}
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js
CHANGED
|
@@ -18,7 +18,13 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
|
|
|
18
18
|
// config.outDir is outside of config.root => it's going to be ignored anyways
|
|
19
19
|
outDirRelativeFromUserRootDir = null;
|
|
20
20
|
}
|
|
21
|
-
assert(outDirRelativeFromUserRootDir === null ||
|
|
21
|
+
assert(outDirRelativeFromUserRootDir === null ||
|
|
22
|
+
/* Not true if outDirRelativeFromUserRootDir starts with a hidden directory (i.e. a directory with a name that starts with `.`)
|
|
23
|
+
!outDirRelativeFromUserRootDir.startsWith('.') &&
|
|
24
|
+
*/
|
|
25
|
+
(!outDirRelativeFromUserRootDir.startsWith('./') &&
|
|
26
|
+
//
|
|
27
|
+
!outDirRelativeFromUserRootDir.startsWith('../')));
|
|
22
28
|
const timeBefore = new Date().getTime();
|
|
23
29
|
let files = [];
|
|
24
30
|
const res = await gitLsFiles(userRootDir, outDirRelativeFromUserRootDir);
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export { loadImportedFile };
|
|
3
3
|
export { loadValueFile };
|
|
4
4
|
export { loadConfigFile };
|
|
5
|
-
import { assert, assertUsage,
|
|
5
|
+
import { assert, assertUsage, hasProp, assertIsNotProductionRuntime } from '../../../../utils.js';
|
|
6
6
|
import { transpileAndExecuteFile } from './transpileAndExecuteFile.js';
|
|
7
7
|
import { assertPlusFileExport } from '../../../../../../shared/page-configs/assertPlusFileExport.js';
|
|
8
8
|
import pc from '@brillout/picocolors';
|
|
@@ -62,7 +62,6 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
|
|
|
62
62
|
const { importPath: importPathAbsolute } = importData;
|
|
63
63
|
const filePathAbsoluteFilesystem = resolveImportPath(importData, configFilePath);
|
|
64
64
|
assertImportPath(filePathAbsoluteFilesystem, importData, configFilePath);
|
|
65
|
-
warnUserLandExtension(importPathAbsolute, configFilePath);
|
|
66
65
|
const filePath = getFilePathResolved({ filePathAbsoluteFilesystem, userRootDir, importPathAbsolute });
|
|
67
66
|
extendsConfigFiles.push(filePath);
|
|
68
67
|
});
|
|
@@ -75,13 +74,6 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
|
|
|
75
74
|
const extendsFilePaths = extendsConfigFiles.map((f) => f.filePathAbsoluteFilesystem);
|
|
76
75
|
return { extendsConfigs, extendsFilePaths };
|
|
77
76
|
}
|
|
78
|
-
function warnUserLandExtension(importPath, configFilePath) {
|
|
79
|
-
// We preserve this feature because we may need it for eject
|
|
80
|
-
assertWarning(isNpmPackageImport(importPath, {
|
|
81
|
-
// Vike config files don't support path aliases. (If they do one day, then Vike will/should be able to resolve path aliases.)
|
|
82
|
-
cannotBePathAlias: true
|
|
83
|
-
}) || importPath.includes('/node_modules/'), `${configFilePath.filePathToShowToUser} uses ${pc.cyan('extends')} to inherit from ${pc.cyan(importPath)} which is a user-land file: this is experimental and may be remove at any time. Reach out to a maintainer if you need this.`, { onlyOnce: true });
|
|
84
|
-
}
|
|
85
77
|
function getExtendsImportData(configFileExports, configFilePath) {
|
|
86
78
|
const { filePathToShowToUser } = configFilePath;
|
|
87
79
|
const configFileExport = getConfigFileExport(configFileExports, filePathToShowToUser);
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js
CHANGED
|
@@ -20,13 +20,22 @@ function resolveImport(configValue, importerFilePath, userRootDir, configEnv, co
|
|
|
20
20
|
const fileExportPathToShowToUser = exportName === 'default' || exportName === configName ? [] : [exportName];
|
|
21
21
|
let filePath;
|
|
22
22
|
if (importPath.startsWith('.')) {
|
|
23
|
-
|
|
23
|
+
assert(importPath.startsWith('./') || importPath.startsWith('../'));
|
|
24
|
+
assertImportPath(filePathAbsoluteFilesystem, importData, importerFilePath);
|
|
25
|
+
filePath = getFilePathResolved({ filePathAbsoluteFilesystem, userRootDir });
|
|
26
|
+
// Imports are included in virtual files, thus the relative path of imports need to resolved.
|
|
24
27
|
// ```
|
|
25
28
|
// [vite] Internal server error: Failed to resolve import "./onPageTransitionHooks" from "virtual:vike:pageConfigValuesAll:client:/pages/index". Does the file exist?
|
|
26
29
|
// ```
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
assertUsage(filePath.filePathAbsoluteUserRootDir, `${importerFilePath.filePathToShowToUser} imports a relative path ${pc.cyan(importPath)} resolving outside of ${userRootDir} which is forbidden: import from a relative path inside ${userRootDir}, or import from a dependency's package.json#exports entry instead`);
|
|
31
|
+
// Alternativey, we can try one of the following but last time we tried none of the following worked.
|
|
32
|
+
// /*
|
|
33
|
+
// assert(filePathAbsoluteFilesystem.startsWith('/'))
|
|
34
|
+
// filePath = `/@fs${filePathAbsoluteFilesystem}`
|
|
35
|
+
// /*/
|
|
36
|
+
// assert(filePathAbsoluteUserRootDir.startsWith('../'))
|
|
37
|
+
// filePathAbsoluteUserRootDir = '/' + filePathAbsoluteUserRootDir
|
|
38
|
+
// //*/
|
|
30
39
|
}
|
|
31
40
|
else {
|
|
32
41
|
// importPath can be:
|
|
@@ -51,28 +60,6 @@ function resolveImport(configValue, importerFilePath, userRootDir, configEnv, co
|
|
|
51
60
|
fileExportPathToShowToUser
|
|
52
61
|
};
|
|
53
62
|
}
|
|
54
|
-
function resolveImportPath_absoluteUserRootDir(filePathAbsoluteFilesystem, importData, configFilePath, userRootDir) {
|
|
55
|
-
assertPosixPath(userRootDir);
|
|
56
|
-
let filePathAbsoluteUserRootDir;
|
|
57
|
-
if (filePathAbsoluteFilesystem.startsWith(userRootDir)) {
|
|
58
|
-
filePathAbsoluteUserRootDir = getVitePathFromAbsolutePath(filePathAbsoluteFilesystem, userRootDir);
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
assertUsage(false, `${configFilePath.filePathToShowToUser} imports from a relative path ${pc.cyan(importData.importPath)} outside of ${userRootDir} which is forbidden: import from a relative path inside ${userRootDir}, or import from a dependency's package.json#exports entry instead`);
|
|
62
|
-
// None of the following works. Seems to be a Vite bug?
|
|
63
|
-
// /*
|
|
64
|
-
// assert(filePathAbsoluteFilesystem.startsWith('/'))
|
|
65
|
-
// filePath = `/@fs${filePathAbsoluteFilesystem}`
|
|
66
|
-
// /*/
|
|
67
|
-
// filePathAbsoluteUserRootDir = path.posix.relative(userRootDir, filePathAbsoluteFilesystem)
|
|
68
|
-
// assert(filePathAbsoluteUserRootDir.startsWith('../'))
|
|
69
|
-
// filePathAbsoluteUserRootDir = '/' + filePathAbsoluteUserRootDir
|
|
70
|
-
// //*/
|
|
71
|
-
}
|
|
72
|
-
assertPosixPath(filePathAbsoluteUserRootDir);
|
|
73
|
-
assert(filePathAbsoluteUserRootDir.startsWith('/'));
|
|
74
|
-
return filePathAbsoluteUserRootDir;
|
|
75
|
-
}
|
|
76
63
|
function resolveImportPath(importData, importerFilePath) {
|
|
77
64
|
const importerFilePathAbsolute = importerFilePath.filePathAbsoluteFilesystem;
|
|
78
65
|
assertPosixPath(importerFilePathAbsolute);
|
|
@@ -93,6 +80,7 @@ function assertImportPath(filePathAbsoluteFilesystem, importData, importerFilePa
|
|
|
93
80
|
: `The import ${pc.cyan(importString)} defined in ${filePathToShowToUser}`;
|
|
94
81
|
const errIntro2 = `${errIntro} couldn't be resolved: does ${importPathString}`;
|
|
95
82
|
if (importPath.startsWith('.')) {
|
|
83
|
+
assert(importPath.startsWith('./') || importPath.startsWith('../'));
|
|
96
84
|
assertUsage(false, `${errIntro2} point to an existing file?`);
|
|
97
85
|
}
|
|
98
86
|
else {
|
|
@@ -119,12 +107,3 @@ function assertFileEnv(filePathForEnvCheck, configEnv, configName) {
|
|
|
119
107
|
function clearFilesEnvMap() {
|
|
120
108
|
filesEnvMap.clear();
|
|
121
109
|
}
|
|
122
|
-
function getVitePathFromAbsolutePath(filePathAbsoluteFilesystem, root) {
|
|
123
|
-
assertPosixPath(filePathAbsoluteFilesystem);
|
|
124
|
-
assertPosixPath(root);
|
|
125
|
-
assert(filePathAbsoluteFilesystem.startsWith(root));
|
|
126
|
-
let vitePath = path.posix.relative(root, filePathAbsoluteFilesystem);
|
|
127
|
-
assert(!vitePath.startsWith('/') && !vitePath.startsWith('.'));
|
|
128
|
-
vitePath = '/' + vitePath;
|
|
129
|
-
return vitePath;
|
|
130
|
-
}
|
|
@@ -2,7 +2,7 @@ export { transformFileImports };
|
|
|
2
2
|
export { parseImportData };
|
|
3
3
|
export { isImportData };
|
|
4
4
|
export type { ImportData };
|
|
5
|
-
declare function transformFileImports(code: string, filePathToShowToUser2: string, pointerImports:
|
|
5
|
+
declare function transformFileImports(code: string, filePathToShowToUser2: string, pointerImports: Record<string, boolean> | 'all', skipWarnings?: true): string | null;
|
|
6
6
|
/**
|
|
7
7
|
* Data Structure holding info about import statement:
|
|
8
8
|
* `import { someExport as someImport } from './some-file'`
|
|
@@ -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 } from '../../../../utils.js';
|
|
10
|
+
import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, assertWarning, isObject, toPosixPath, assertUsage, isJavaScriptFile, createDebugger, assertPathIsFilesystemAbsolute } 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';
|
|
@@ -79,98 +79,96 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
79
79
|
// Esbuild still sometimes removes unused imports because of TypeScript: https://github.com/evanw/esbuild/issues/3034
|
|
80
80
|
treeShaking: false,
|
|
81
81
|
minify: false,
|
|
82
|
-
metafile:
|
|
83
|
-
bundle:
|
|
82
|
+
metafile: true,
|
|
83
|
+
bundle: true
|
|
84
84
|
};
|
|
85
|
-
let pointerImports;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
setup(build) {
|
|
99
|
-
// https://github.com/evanw/esbuild/issues/3095#issuecomment-1546916366
|
|
85
|
+
let pointerImports = {};
|
|
86
|
+
options.plugins = [
|
|
87
|
+
// Determine whether an import should be:
|
|
88
|
+
// - A pointer import
|
|
89
|
+
// - Externalized
|
|
90
|
+
{
|
|
91
|
+
name: 'vike-esbuild',
|
|
92
|
+
setup(build) {
|
|
93
|
+
// https://github.com/brillout/esbuild-playground
|
|
94
|
+
build.onResolve({ filter: /.*/ }, async (args) => {
|
|
95
|
+
if (args.kind !== 'import-statement')
|
|
96
|
+
return;
|
|
97
|
+
// Avoid infinite loop: https://github.com/evanw/esbuild/issues/3095#issuecomment-1546916366
|
|
100
98
|
const useEsbuildResolver = 'useEsbuildResolver';
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
// - This is temporary, see comment below.
|
|
122
|
-
const isVikeExtensionConfigImport = resolved.path.endsWith('+config.js');
|
|
123
|
-
const isPointerImport =
|
|
99
|
+
if (args.pluginData?.[useEsbuildResolver])
|
|
100
|
+
return;
|
|
101
|
+
const { path, ...opts } = args;
|
|
102
|
+
opts.pluginData = { [useEsbuildResolver]: true };
|
|
103
|
+
const resolved = await build.resolve(path, opts);
|
|
104
|
+
if (resolved.errors.length > 0) {
|
|
105
|
+
/* We could do the following to let Node.js throw the error, but we don't because the error shown by esbuild is prettier: the Node.js error refers to the transpiled [build-f7i251e0iwnw]+config.ts.mjs file which isn't that nice, whereas esbuild refers to the source +config.ts file.
|
|
106
|
+
pointerImports[args.path] = false
|
|
107
|
+
return { external: true }
|
|
108
|
+
*/
|
|
109
|
+
// Let esbuild throw the error. (It throws a nice & pretty error.)
|
|
110
|
+
cleanEsbuildErrors(resolved.errors);
|
|
111
|
+
return resolved;
|
|
112
|
+
}
|
|
113
|
+
assert(resolved.path);
|
|
114
|
+
resolved.path = toPosixPath(resolved.path);
|
|
115
|
+
// vike-{react,vue,solid} follow the convention that their config export resolves to a file named +config.js
|
|
116
|
+
// - This is temporary, see comment below.
|
|
117
|
+
const isVikeExtensionConfigImport = resolved.path.endsWith('+config.js');
|
|
118
|
+
const isPointerImport = transformImports === 'all' ||
|
|
124
119
|
// .jsx, .vue, .svg, ... => obviously not config code
|
|
125
120
|
!isJavaScriptFile(resolved.path) ||
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
name: 'vike:dependency-tracker',
|
|
153
|
-
setup(b) {
|
|
154
|
-
b.onLoad({ filter: /./ }, (args) => {
|
|
155
|
-
// We collect the dependency `args.path` in case the bulid fails (upon build error => error is thrown => no metafile)
|
|
156
|
-
let { path } = args;
|
|
157
|
-
path = toPosixPath(path);
|
|
158
|
-
vikeConfigDependencies.add(path);
|
|
159
|
-
return undefined;
|
|
160
|
-
});
|
|
161
|
-
/* To exhaustively collect all dependencies upon build failure, we would also need to use onResolve().
|
|
162
|
-
* - Because onLoad() isn't call if the config dependency can't be resolved.
|
|
163
|
-
* - For example, the following breaks auto-reload (the config is stuck in its error state and the user needs to touch the importer for the config to reload):
|
|
164
|
-
* ```bash
|
|
165
|
-
* mv ./some-config-dependency.js /tmp/ && mv /tmp/some-config-dependency.js .
|
|
166
|
-
* ```
|
|
167
|
-
* - But implementing a fix is complex and isn't worth it.
|
|
168
|
-
b.onResolve(...)
|
|
169
|
-
*/
|
|
170
|
-
}
|
|
121
|
+
// Import of a Vike extension config => make it a pointer import because we want to show nice error messages (that can display whether a configas been set by the user or by a Vike extension).
|
|
122
|
+
// - We should have Node.js directly load vike-{react,vue,solid} while enforcing Vike extensions to set 'name' in their +config.js file.
|
|
123
|
+
// - vike@0.4.162 already started soft-requiring Vike extensions to set the name config
|
|
124
|
+
isVikeExtensionConfigImport ||
|
|
125
|
+
// Cannot be resolved by esbuild => take a leap of faith and make it a pointer import.
|
|
126
|
+
// - For example if esbuild cannot resolve a path alias while Vite can.
|
|
127
|
+
// - When tsconfig.js#compilerOptions.paths is set, then esbuild is able to resolve the path alias.
|
|
128
|
+
resolved.errors.length > 0;
|
|
129
|
+
pointerImports[resolved.path] = isPointerImport;
|
|
130
|
+
assertPosixPath(resolved.path);
|
|
131
|
+
const isExternal = isPointerImport ||
|
|
132
|
+
// Performance: npm package imports that aren't pointer imports can be externalized. For example, if Vike eventually adds support for setting Vite configs in the vike.config.js file, then the user may import a Vite plugin in his vike.config.js file. (We could as well let esbuild always transpile /node_modules/ code but it would be useless and would unnecessarily slow down transpilation.)
|
|
133
|
+
resolved.path.includes('/node_modules/');
|
|
134
|
+
if (debug.isActivated)
|
|
135
|
+
debug('onResolved()', { args, resolved, isPointerImport, isExternal });
|
|
136
|
+
// We need esbuild to resolve path aliases so that we can use:
|
|
137
|
+
// isNpmPackageImport(str, { cannotBePathAlias: true })
|
|
138
|
+
// assertIsNpmPackageImport()
|
|
139
|
+
assertPathIsFilesystemAbsolute(resolved.path);
|
|
140
|
+
if (isExternal) {
|
|
141
|
+
return { external: true, path: resolved.path };
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
return resolved;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
171
147
|
}
|
|
172
|
-
|
|
173
|
-
|
|
148
|
+
},
|
|
149
|
+
// Track dependencies
|
|
150
|
+
{
|
|
151
|
+
name: 'vike:dependency-tracker',
|
|
152
|
+
setup(b) {
|
|
153
|
+
b.onLoad({ filter: /./ }, (args) => {
|
|
154
|
+
// We collect the dependency `args.path` in case the bulid fails (upon build error => error is thrown => no metafile)
|
|
155
|
+
let { path } = args;
|
|
156
|
+
path = toPosixPath(path);
|
|
157
|
+
vikeConfigDependencies.add(path);
|
|
158
|
+
return undefined;
|
|
159
|
+
});
|
|
160
|
+
/* To exhaustively collect all dependencies upon build failure, we would also need to use onResolve().
|
|
161
|
+
* - Because onLoad() isn't call if the config dependency can't be resolved.
|
|
162
|
+
* - For example, the following breaks auto-reload (the config is stuck in its error state and the user needs to touch the importer for the config to reload):
|
|
163
|
+
* ```bash
|
|
164
|
+
* mv ./some-config-dependency.js /tmp/ && mv /tmp/some-config-dependency.js .
|
|
165
|
+
* ```
|
|
166
|
+
* - But implementing a fix is complex and isn't worth it.
|
|
167
|
+
b.onResolve(...)
|
|
168
|
+
*/
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
];
|
|
174
172
|
let result;
|
|
175
173
|
try {
|
|
176
174
|
result = await build(options);
|
|
@@ -180,15 +178,13 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
180
178
|
throw err;
|
|
181
179
|
}
|
|
182
180
|
// Track dependencies
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
});
|
|
191
|
-
}
|
|
181
|
+
assert(result.metafile);
|
|
182
|
+
Object.keys(result.metafile.inputs).forEach((filePathRelative) => {
|
|
183
|
+
filePathRelative = toPosixPath(filePathRelative);
|
|
184
|
+
assertPosixPath(userRootDir);
|
|
185
|
+
const filePathAbsoluteFilesystem = path.posix.join(userRootDir, filePathRelative);
|
|
186
|
+
vikeConfigDependencies.add(filePathAbsoluteFilesystem);
|
|
187
|
+
});
|
|
192
188
|
const code = result.outputFiles[0].text;
|
|
193
189
|
assert(typeof code === 'string');
|
|
194
190
|
return { code, pointerImports };
|
|
@@ -310,3 +306,23 @@ function getErrIntroMsg(operation, filePath) {
|
|
|
310
306
|
].join(' ');
|
|
311
307
|
return msg;
|
|
312
308
|
}
|
|
309
|
+
function cleanEsbuildErrors(errors) {
|
|
310
|
+
errors.forEach((e) => (e.notes = e.notes.filter((note) =>
|
|
311
|
+
// Remove note:
|
|
312
|
+
// ```shell
|
|
313
|
+
// You can mark the path "#root/renderer/onRenderHtml_typo" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle.
|
|
314
|
+
// ```
|
|
315
|
+
//
|
|
316
|
+
// From error:
|
|
317
|
+
// ```shell
|
|
318
|
+
// ✘ [ERROR] Could not resolve "#root/renderer/onRenderHtml_typo" [plugin vike-esbuild]
|
|
319
|
+
//
|
|
320
|
+
// renderer/+config.h.js:1:29:
|
|
321
|
+
// 1 │ import { onRenderHtml } from "#root/renderer/onRenderHtml_typo"
|
|
322
|
+
// ╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
323
|
+
//
|
|
324
|
+
// You can mark the path "#root/renderer/onRenderHtml_typo" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle.
|
|
325
|
+
//
|
|
326
|
+
// ```
|
|
327
|
+
!note.text.includes('as external to exclude it from the bundle'))));
|
|
328
|
+
}
|
|
@@ -87,7 +87,12 @@ function getFilePathAbsoluteUserRootDir({ filePathAbsoluteFilesystem, userRootDi
|
|
|
87
87
|
assert(filePathRelative.startsWith('../'));
|
|
88
88
|
return null;
|
|
89
89
|
}
|
|
90
|
-
assert(!filePathRelative.startsWith('
|
|
90
|
+
assert(!filePathRelative.startsWith('/') &&
|
|
91
|
+
/* Not true if filePathRelative starts with a hidden directory (i.e. a directory with a name that starts with `.`)
|
|
92
|
+
!filePathRelative.startsWith('.') &&
|
|
93
|
+
*/
|
|
94
|
+
!filePathRelative.startsWith('./') &&
|
|
95
|
+
!filePathRelative.startsWith('../'));
|
|
91
96
|
const filePathAbsoluteUserRootDir = `/${filePathRelative}`;
|
|
92
97
|
assert(filePathAbsoluteUserRootDir === getFilePathAbsoluteUserRootDir2(filePathAbsoluteFilesystem, userRootDir));
|
|
93
98
|
return filePathAbsoluteUserRootDir;
|
|
@@ -6,10 +6,10 @@ import { assertPosixPath } from './filesystemPathHandling.js';
|
|
|
6
6
|
function assertPathIsFilesystemAbsolute(p) {
|
|
7
7
|
assertPosixPath(p);
|
|
8
8
|
assert(!p.startsWith('/@fs/'));
|
|
9
|
-
if (process.platform
|
|
10
|
-
assert(
|
|
9
|
+
if (process.platform !== 'win32') {
|
|
10
|
+
assert(p.startsWith('/'));
|
|
11
11
|
}
|
|
12
12
|
else {
|
|
13
|
-
assert(
|
|
13
|
+
assert(path.win32.isAbsolute(p));
|
|
14
14
|
}
|
|
15
15
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { projectInfo };
|
|
2
2
|
export { PROJECT_VERSION };
|
|
3
|
-
declare const PROJECT_VERSION: "0.4.
|
|
3
|
+
declare const PROJECT_VERSION: "0.4.168-commit-ce94f5c";
|
|
4
4
|
declare const projectInfo: {
|
|
5
5
|
projectName: "Vike";
|
|
6
|
-
projectVersion: "0.4.
|
|
6
|
+
projectVersion: "0.4.168-commit-ce94f5c";
|
|
7
7
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vike",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.168-commit-ce94f5c",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "tsc --watch",
|
|
6
6
|
"build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"@brillout/json-serializer": "^0.5.8",
|
|
17
17
|
"@brillout/picocolors": "^1.0.10",
|
|
18
18
|
"@brillout/require-shim": "^0.1.2",
|
|
19
|
-
"@brillout/vite-plugin-server-entry": "^0.4.
|
|
19
|
+
"@brillout/vite-plugin-server-entry": "^0.4.5",
|
|
20
20
|
"acorn": "^8.0.0",
|
|
21
21
|
"cac": "^6.0.0",
|
|
22
22
|
"es-module-lexer": "^1.0.0",
|