vike 0.4.160-commit-a1101c1 → 0.4.160-commit-30d535e
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/autoFullBuild.js +2 -2
- package/dist/cjs/node/plugin/plugins/buildConfig.js +9 -0
- package/dist/cjs/node/plugin/plugins/commonConfig.js +1 -1
- package/dist/cjs/node/plugin/plugins/config/stemUtils.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +28 -46
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{loadFileConfigEnv.js → loadFileAtConfigTime.js} +5 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +33 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformImports.js → transformFileImports.js} +7 -7
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +21 -27
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +150 -110
- package/dist/cjs/node/plugin/utils.js +1 -2
- package/dist/cjs/node/prerender/runPrerender.js +12 -5
- package/dist/cjs/node/runtime/globalContext.js +7 -4
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
- package/dist/cjs/node/runtime/renderPage/{logHintForCjsEsmError.js → logErrorHint.js} +81 -43
- package/dist/cjs/node/runtime/renderPage/loggerProd.js +3 -3
- package/dist/cjs/node/runtime/utils.js +1 -1
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +53 -26
- package/dist/cjs/shared/route/executeGuardHook.js +3 -2
- package/dist/cjs/shared/utils.js +0 -1
- package/dist/cjs/utils/{findUserPackageJsonPath.js → findFile.js} +11 -8
- package/dist/cjs/utils/nodeEnv.js +23 -1
- package/dist/cjs/utils/objectKeys.js +19 -3
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/cjs/utils/sorter.js +62 -1
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +2 -2
- package/dist/esm/node/plugin/plugins/buildConfig.js +10 -1
- package/dist/esm/node/plugin/plugins/commonConfig.js +2 -2
- package/dist/esm/node/plugin/plugins/config/stemUtils.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +0 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +39 -12
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +29 -47
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{loadFileConfigEnv.js → loadFileAtConfigTime.js} +4 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.d.ts +5 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +27 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformImports.d.ts → transformFileImports.d.ts} +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformImports.js → transformFileImports.js} +6 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +20 -26
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +2 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +149 -109
- package/dist/esm/node/plugin/utils.d.ts +1 -2
- package/dist/esm/node/plugin/utils.js +1 -2
- package/dist/esm/node/prerender/runPrerender.js +13 -6
- package/dist/esm/node/runtime/globalContext.js +8 -5
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
- package/dist/esm/node/runtime/renderPage/logErrorHint.d.ts +8 -0
- package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError.js → logErrorHint.js} +80 -42
- package/dist/esm/node/runtime/renderPage/loggerProd.js +3 -3
- package/dist/esm/node/runtime/utils.d.ts +1 -1
- package/dist/esm/node/runtime/utils.js +1 -1
- package/dist/esm/shared/page-configs/PageConfig.d.ts +2 -0
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +53 -26
- package/dist/esm/shared/route/executeGuardHook.js +3 -2
- package/dist/esm/shared/utils.d.ts +0 -1
- package/dist/esm/shared/utils.js +0 -1
- package/dist/esm/utils/findFile.d.ts +3 -0
- package/dist/esm/utils/findFile.js +21 -0
- package/dist/esm/utils/nodeEnv.d.ts +4 -0
- package/dist/esm/utils/nodeEnv.js +19 -0
- package/dist/esm/utils/objectKeys.d.ts +10 -1
- package/dist/esm/utils/objectKeys.js +20 -3
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/dist/esm/utils/sorter.d.ts +59 -0
- package/dist/esm/utils/sorter.js +61 -0
- package/package.json +1 -1
- package/dist/cjs/utils/objectEntries.js +0 -8
- package/dist/esm/node/runtime/renderPage/logHintForCjsEsmError.d.ts +0 -13
- package/dist/esm/utils/findUserPackageJsonPath.d.ts +0 -2
- package/dist/esm/utils/findUserPackageJsonPath.js +0 -18
- package/dist/esm/utils/objectEntries.d.ts +0 -4
- package/dist/esm/utils/objectEntries.js +0 -5
- /package/dist/cjs/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.js +0 -0
- /package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{loadFileConfigEnv.d.ts → loadFileAtConfigTime.d.ts} +0 -0
- /package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.d.ts +0 -0
- /package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.js +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { commonConfig };
|
|
2
|
-
import { assert, assertWarning,
|
|
2
|
+
import { assert, assertWarning, findFile } from '../utils.js';
|
|
3
3
|
import { assertRollupInput } from './buildConfig.js';
|
|
4
4
|
import { installRequireShim_setUserRootDir } from '@brillout/require-shim';
|
|
5
5
|
import pc from '@brillout/picocolors';
|
|
@@ -70,7 +70,7 @@ function workaroundCI(config) {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
function assertEsm(userViteRoot) {
|
|
73
|
-
const packageJsonPath =
|
|
73
|
+
const packageJsonPath = findFile('package.json', userViteRoot);
|
|
74
74
|
if (!packageJsonPath)
|
|
75
75
|
return;
|
|
76
76
|
const packageJson = require_(packageJsonPath);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Move to standalone package? E.g. https://www.npmjs.com/package/stem
|
|
2
2
|
export { getStemPackages };
|
|
3
3
|
import path from 'path';
|
|
4
|
-
import { assert, assertUsage, assertWarning, toPosixPath, assertPosixPath, getDependencyRootDir,
|
|
4
|
+
import { assert, assertUsage, assertWarning, toPosixPath, assertPosixPath, getDependencyRootDir, findFile } from '../../utils.js';
|
|
5
5
|
import { import_ } from '@brillout/import';
|
|
6
6
|
import { createRequire } from 'module';
|
|
7
7
|
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
@@ -48,7 +48,7 @@ async function getStemPackages(userAppRootDir) {
|
|
|
48
48
|
return stemPackages;
|
|
49
49
|
}
|
|
50
50
|
function findUserRootDir(userAppRootDir) {
|
|
51
|
-
const userPkgJsonPath =
|
|
51
|
+
const userPkgJsonPath = findFile('package.json', userAppRootDir);
|
|
52
52
|
assertUsage(userPkgJsonPath, `Couldn't find package.json in any parent directory starting from ${userAppRootDir}`);
|
|
53
53
|
return toPosixPath(path.dirname(userPkgJsonPath));
|
|
54
54
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { configDefinitionsBuiltIn };
|
|
2
2
|
export { configDefinitionsBuiltInGlobal };
|
|
3
3
|
export type { ConfigDefinition };
|
|
4
|
+
export type { ConfigDefinitions };
|
|
4
5
|
export type { ConfigDefinitionInternal };
|
|
5
6
|
export type { ConfigNameGlobal };
|
|
6
7
|
export type { ConfigEffect };
|
|
@@ -54,6 +55,7 @@ type ConfigDefinitionInternal = Omit<ConfigDefinition, 'env'> & {
|
|
|
54
55
|
_userEffectDefinedAt?: DefinedAtFileFullInfo;
|
|
55
56
|
env: ConfigEnvInternal;
|
|
56
57
|
};
|
|
58
|
+
type ConfigDefinitions = Record<string, ConfigDefinitionInternal>;
|
|
57
59
|
type ConfigDefinitionsBuiltIn = Record<ConfigNameBuiltIn, ConfigDefinitionInternal>;
|
|
58
60
|
declare const configDefinitionsBuiltIn: ConfigDefinitionsBuiltIn;
|
|
59
61
|
type ConfigNameGlobal = 'onPrerenderStart' | 'onBeforeRoute' | 'prerender' | 'extensions' | 'disableAutoFullBuild' | 'includeAssetsImportedByServer' | 'baseAssets' | 'baseServer' | 'redirects' | 'trailingSlash' | 'disableUrlNormalization';
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js
CHANGED
|
@@ -44,11 +44,7 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
|
|
|
44
44
|
p = toPosixPath(p);
|
|
45
45
|
assert(!p.startsWith(userRootDir));
|
|
46
46
|
const filePathRelativeToUserRootDir = path.posix.join('/', p);
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
filePathRelativeToUserRootDir,
|
|
50
|
-
filePathAbsoluteFilesystem
|
|
51
|
-
};
|
|
47
|
+
return { filePathRelativeToUserRootDir };
|
|
52
48
|
});
|
|
53
49
|
return plusFiles;
|
|
54
50
|
}
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts
CHANGED
|
@@ -5,26 +5,53 @@ export { getLocationId };
|
|
|
5
5
|
export { sortAfterInheritanceOrder };
|
|
6
6
|
export { isGlobalLocation };
|
|
7
7
|
export { applyFilesystemRoutingRootEffect };
|
|
8
|
+
export type { LocationId };
|
|
8
9
|
export { getLogicalPath };
|
|
9
10
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* The `locationId` value is used for filesystem inheritance.
|
|
12
|
+
*
|
|
13
|
+
* Each config value is assigned with a `locationId` value. That's the source-of-truth for determining inheritance between config values.
|
|
14
|
+
*
|
|
15
|
+
* For Vike extensions, `locationId` is different than the config value's `definedAt`, for example the `onRenderHtml()` hook of `vike-react`:
|
|
16
|
+
* - `locationId === '/pages'` (the directory of `/pages/+config.h.js` which extends `vike-react`)
|
|
17
|
+
* - `definedAt.filePathAbsoluteFilesystem === '/home/rom/code/my-vike-app/node_modules/vike-react/dist/renderer/onRenderHtml.js'` (the file where the value is defined)
|
|
18
|
+
*
|
|
19
|
+
* This is an important distinction because the Vike extension's config should only apply to where it's being extended from, for example:
|
|
20
|
+
* ```js
|
|
21
|
+
* // /pages/admin/+config.h.js
|
|
22
|
+
* import vikeVue from 'vike-vue/config'
|
|
23
|
+
* // Should only apply to /pages/admin/**
|
|
24
|
+
* export default { extends: [vikeVue] }
|
|
25
|
+
* ```
|
|
26
|
+
* ```js
|
|
27
|
+
* // /pages/marketing/+config.h.js
|
|
28
|
+
* import vikeReact from 'vike-react/config'
|
|
29
|
+
* // Should only apply to /pages/marketing/**
|
|
30
|
+
* export default { extends: [vikeReact] }
|
|
31
|
+
* ```
|
|
13
32
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
33
|
+
type LocationId = string & {
|
|
34
|
+
__brand: 'LocationId';
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* `getLocationId('/pages/some-page/+Page.js')` => `'/pages/some-page'`
|
|
38
|
+
* `getLocationId('/renderer/+config.js')` => `'/renderer'`
|
|
39
|
+
*
|
|
40
|
+
* The value `locationId` is always a user-land path, because Filesystem Routing/Inheritance only applies to the user-land (Vike never uses Filesystem Routing/Inheritance for `node_modules/**`).
|
|
41
|
+
*/
|
|
42
|
+
declare function getLocationId(filePathRelativeToUserRootDir: string): LocationId;
|
|
43
|
+
/** Filesystem Routing: get the URL */
|
|
44
|
+
declare function getFilesystemRouteString(locationId: LocationId): string;
|
|
17
45
|
/**
|
|
18
46
|
* getLogicalPath('/pages/some-page', ['pages']) => '/some-page'
|
|
19
|
-
* getLogicalPath('some-npm-pkg/renderer', ['renderer']) => '/'
|
|
20
47
|
*/
|
|
21
|
-
declare function getLogicalPath(
|
|
48
|
+
declare function getLogicalPath(locationId: LocationId, removeDirs: string[]): string;
|
|
22
49
|
/** Whether configs defined in `locationId` apply in every `locationIds` */
|
|
23
|
-
declare function isGlobalLocation(locationId:
|
|
24
|
-
declare function sortAfterInheritanceOrder(locationId1:
|
|
50
|
+
declare function isGlobalLocation(locationId: LocationId, locationIds: LocationId[]): boolean;
|
|
51
|
+
declare function sortAfterInheritanceOrder(locationId1: LocationId, locationId2: LocationId, locationIdPage: LocationId): -1 | 1 | 0;
|
|
25
52
|
/** Whether configs defined at `locationId1` also apply at `locationId2` */
|
|
26
|
-
declare function isInherited(locationId1:
|
|
27
|
-
declare function getFilesystemRouteDefinedBy(locationId:
|
|
53
|
+
declare function isInherited(locationId1: LocationId, locationId2: LocationId): boolean;
|
|
54
|
+
declare function getFilesystemRouteDefinedBy(locationId: LocationId): string;
|
|
28
55
|
declare function applyFilesystemRoutingRootEffect(routeFilesystem: string, filesystemRoutingRootEffect: {
|
|
29
56
|
before: string;
|
|
30
57
|
after: string;
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js
CHANGED
|
@@ -7,40 +7,47 @@ export { isGlobalLocation };
|
|
|
7
7
|
export { applyFilesystemRoutingRootEffect };
|
|
8
8
|
// For ./filesystemRouting.spec.ts
|
|
9
9
|
export { getLogicalPath };
|
|
10
|
-
import { assert, assertPosixPath,
|
|
10
|
+
import { assert, assertPosixPath, higherFirst } from '../../../../utils.js';
|
|
11
11
|
/**
|
|
12
|
-
* getLocationId('/pages/some-page/+Page.js') => '/pages/some-page'
|
|
13
|
-
* getLocationId('/
|
|
14
|
-
*
|
|
12
|
+
* `getLocationId('/pages/some-page/+Page.js')` => `'/pages/some-page'`
|
|
13
|
+
* `getLocationId('/renderer/+config.js')` => `'/renderer'`
|
|
14
|
+
*
|
|
15
|
+
* The value `locationId` is always a user-land path, because Filesystem Routing/Inheritance only applies to the user-land (Vike never uses Filesystem Routing/Inheritance for `node_modules/**`).
|
|
15
16
|
*/
|
|
16
|
-
function getLocationId(
|
|
17
|
-
|
|
17
|
+
function getLocationId(
|
|
18
|
+
// We always determine `locationId` from a real user-land file: the `locationId` for Vike extensions is the `locationId` of the the user's `+config.h.js` that extends the Vike extension.
|
|
19
|
+
filePathRelativeToUserRootDir) {
|
|
20
|
+
assertPosixPath(filePathRelativeToUserRootDir);
|
|
21
|
+
assert(filePathRelativeToUserRootDir.startsWith('/'));
|
|
22
|
+
const locationId = removeFilename(filePathRelativeToUserRootDir);
|
|
18
23
|
assertLocationId(locationId);
|
|
19
24
|
return locationId;
|
|
20
25
|
}
|
|
21
|
-
/**
|
|
26
|
+
/** Filesystem Routing: get the URL */
|
|
22
27
|
function getFilesystemRouteString(locationId) {
|
|
23
28
|
return getLogicalPath(locationId, ['renderer', 'pages', 'src', 'index']);
|
|
24
29
|
}
|
|
25
|
-
/**
|
|
26
|
-
function getInheritanceRoot(
|
|
27
|
-
return getLogicalPath(
|
|
30
|
+
/** Filesystem Inheritance: get the apply root */
|
|
31
|
+
function getInheritanceRoot(locationId) {
|
|
32
|
+
return getLogicalPath(locationId, ['renderer']);
|
|
28
33
|
}
|
|
29
34
|
/**
|
|
30
35
|
* getLogicalPath('/pages/some-page', ['pages']) => '/some-page'
|
|
31
|
-
* getLogicalPath('some-npm-pkg/renderer', ['renderer']) => '/'
|
|
32
36
|
*/
|
|
33
|
-
function getLogicalPath(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return someDir;
|
|
37
|
+
function getLogicalPath(locationId, removeDirs) {
|
|
38
|
+
let logicalPath = removeDirectories(locationId, removeDirs);
|
|
39
|
+
assertIsPath(logicalPath);
|
|
40
|
+
return logicalPath;
|
|
38
41
|
}
|
|
39
42
|
/** Whether configs defined in `locationId` apply in every `locationIds` */
|
|
40
43
|
function isGlobalLocation(locationId, locationIds) {
|
|
41
44
|
return locationIds.every((locId) => isInherited(locationId, locId) || locationIsRendererDir(locId));
|
|
42
45
|
}
|
|
43
46
|
function sortAfterInheritanceOrder(locationId1, locationId2, locationIdPage) {
|
|
47
|
+
assertLocationId(locationId1);
|
|
48
|
+
assertLocationId(locationId2);
|
|
49
|
+
if (locationId1 === locationId2)
|
|
50
|
+
return 0;
|
|
44
51
|
const inheritanceRoot1 = getInheritanceRoot(locationId1);
|
|
45
52
|
const inheritanceRoot2 = getInheritanceRoot(locationId2);
|
|
46
53
|
const inheritanceRootPage = getInheritanceRoot(locationIdPage);
|
|
@@ -56,15 +63,10 @@ function sortAfterInheritanceOrder(locationId1, locationId2, locationIdPage) {
|
|
|
56
63
|
assert(inheritanceRoot1.length !== inheritanceRoot2.length);
|
|
57
64
|
return higherFirst((inheritanceRoot) => inheritanceRoot.length)(inheritanceRoot1, inheritanceRoot2);
|
|
58
65
|
}
|
|
59
|
-
// Should be true since we aggregate interface files by locationId
|
|
60
|
-
assert(locationId1 !== locationId2);
|
|
61
66
|
// locationId1 first, i.e. `indexOf(locationId1) < indexOf(locationId2)`
|
|
62
67
|
const locationId1First = -1;
|
|
63
68
|
// locationId2 first, i.e. `indexOf(locationId2) < indexOf(locationId1)`
|
|
64
69
|
const locationId2First = 1;
|
|
65
|
-
if (locationIsNpmPackage(locationId1) !== locationIsNpmPackage(locationId2)) {
|
|
66
|
-
return locationIsNpmPackage(locationId1) ? locationId2First : locationId1First;
|
|
67
|
-
}
|
|
68
70
|
if (locationIsRendererDir(locationId1) !== locationIsRendererDir(locationId2)) {
|
|
69
71
|
return locationIsRendererDir(locationId1) ? locationId2First : locationId1First;
|
|
70
72
|
}
|
|
@@ -75,9 +77,6 @@ function sortAfterInheritanceOrder(locationId1, locationId2, locationIdPage) {
|
|
|
75
77
|
}
|
|
76
78
|
return locationId1 > locationId2 ? locationId1First : locationId2First;
|
|
77
79
|
}
|
|
78
|
-
function locationIsNpmPackage(locationId) {
|
|
79
|
-
return !locationId.startsWith('/');
|
|
80
|
-
}
|
|
81
80
|
function locationIsRendererDir(locationId) {
|
|
82
81
|
return locationId.split('/').includes('renderer');
|
|
83
82
|
}
|
|
@@ -87,19 +86,6 @@ function isInherited(locationId1, locationId2) {
|
|
|
87
86
|
const inheritanceRoot2 = getInheritanceRoot(locationId2);
|
|
88
87
|
return startsWith(inheritanceRoot2, inheritanceRoot1);
|
|
89
88
|
}
|
|
90
|
-
function removeNpmPackageName(somePath) {
|
|
91
|
-
if (!isNpmPackageImport(somePath)) {
|
|
92
|
-
assert(somePath.startsWith('/'));
|
|
93
|
-
return somePath;
|
|
94
|
-
}
|
|
95
|
-
const importPath = getNpmPackageImportPath(somePath);
|
|
96
|
-
if (!importPath)
|
|
97
|
-
return '/';
|
|
98
|
-
assertPosixPath(importPath);
|
|
99
|
-
assert(!importPath.startsWith('/'));
|
|
100
|
-
somePath = '/' + importPath;
|
|
101
|
-
return somePath;
|
|
102
|
-
}
|
|
103
89
|
function removeDirectories(somePath, removeDirs) {
|
|
104
90
|
assertPosixPath(somePath);
|
|
105
91
|
somePath = somePath
|
|
@@ -110,17 +96,13 @@ function removeDirectories(somePath, removeDirs) {
|
|
|
110
96
|
somePath = '/';
|
|
111
97
|
return somePath;
|
|
112
98
|
}
|
|
113
|
-
function removeFilename(
|
|
114
|
-
|
|
115
|
-
assert(filePathAbsoluteVite.startsWith('/') || isNpmPackageImport(filePathAbsoluteVite));
|
|
99
|
+
function removeFilename(filePathRelativeToUserRootDir) {
|
|
100
|
+
const filePathParts = filePathRelativeToUserRootDir.split('/');
|
|
116
101
|
{
|
|
117
|
-
const filename =
|
|
118
|
-
|
|
119
|
-
assert(optional);
|
|
120
|
-
return filePathAbsoluteVite;
|
|
121
|
-
}
|
|
102
|
+
const filename = filePathParts.slice(-1)[0];
|
|
103
|
+
assert(filename.includes('.'));
|
|
122
104
|
}
|
|
123
|
-
let locationId =
|
|
105
|
+
let locationId = filePathParts.slice(0, -1).join('/');
|
|
124
106
|
if (locationId === '')
|
|
125
107
|
locationId = '/';
|
|
126
108
|
assertLocationId(locationId);
|
|
@@ -142,7 +124,7 @@ function applyFilesystemRoutingRootEffect(routeFilesystem, filesystemRoutingRoot
|
|
|
142
124
|
return routeFilesystem;
|
|
143
125
|
}
|
|
144
126
|
function assertLocationId(locationId) {
|
|
145
|
-
assert(locationId.startsWith('/')
|
|
127
|
+
assert(locationId.startsWith('/'));
|
|
146
128
|
assert(!locationId.endsWith('/') || locationId === '/');
|
|
147
129
|
}
|
|
148
130
|
function assertIsPath(logicalPath) {
|
|
@@ -6,7 +6,7 @@ import { assertPosixPath, assert, assertUsage, assertWarning, hasProp, assertIsN
|
|
|
6
6
|
import { transpileAndExecuteFile } from './transpileAndExecuteFile.js';
|
|
7
7
|
import { assertPlusFileExport } from '../../../../../../shared/page-configs/assertPlusFileExport.js';
|
|
8
8
|
import pc from '@brillout/picocolors';
|
|
9
|
-
import { parseImportData } from './
|
|
9
|
+
import { parseImportData } from './transformFileImports.js';
|
|
10
10
|
import { getConfigFileExport } from '../getConfigFileExport.js';
|
|
11
11
|
import { assertImportPath, resolveImportPath } from './resolveImportPath.js';
|
|
12
12
|
assertIsNotProductionRuntime();
|
|
@@ -14,7 +14,7 @@ assertIsNotProductionRuntime();
|
|
|
14
14
|
async function loadImportedFile(import_, userRootDir, importedFilesLoaded) {
|
|
15
15
|
const f = import_.filePathAbsoluteFilesystem;
|
|
16
16
|
if (!importedFilesLoaded[f]) {
|
|
17
|
-
importedFilesLoaded[f] = transpileAndExecuteFile(import_,
|
|
17
|
+
importedFilesLoaded[f] = transpileAndExecuteFile(import_, false, userRootDir).then((r) => r.fileExports);
|
|
18
18
|
}
|
|
19
19
|
const fileExports = await importedFilesLoaded[f];
|
|
20
20
|
const fileExport = fileExports[import_.fileExportName];
|
|
@@ -22,7 +22,7 @@ async function loadImportedFile(import_, userRootDir, importedFilesLoaded) {
|
|
|
22
22
|
}
|
|
23
23
|
// Load +{configName}.js
|
|
24
24
|
async function loadValueFile(interfaceValueFile, configName, userRootDir) {
|
|
25
|
-
const { fileExports } = await transpileAndExecuteFile(interfaceValueFile.filePath,
|
|
25
|
+
const { fileExports } = await transpileAndExecuteFile(interfaceValueFile.filePath, false, userRootDir);
|
|
26
26
|
const { filePathToShowToUser } = interfaceValueFile.filePath;
|
|
27
27
|
assertPlusFileExport(fileExports, filePathToShowToUser, configName);
|
|
28
28
|
Object.entries(fileExports).forEach(([exportName, configValue]) => {
|
|
@@ -34,7 +34,7 @@ async function loadValueFile(interfaceValueFile, configName, userRootDir) {
|
|
|
34
34
|
async function loadConfigFile(configFilePath, userRootDir, visited, isConfigOfExtension) {
|
|
35
35
|
const { filePathAbsoluteFilesystem } = configFilePath;
|
|
36
36
|
assertNoInfiniteLoop(visited, filePathAbsoluteFilesystem);
|
|
37
|
-
const { fileExports } = await transpileAndExecuteFile(configFilePath,
|
|
37
|
+
const { fileExports } = await transpileAndExecuteFile(configFilePath, !isConfigOfExtension, userRootDir, isConfigOfExtension);
|
|
38
38
|
const { extendsConfigs, extendsFilePaths } = await loadExtendsConfigs(fileExports, configFilePath, userRootDir, [
|
|
39
39
|
...visited,
|
|
40
40
|
filePathAbsoluteFilesystem
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { resolveFilePathRelativeToUserRootDir };
|
|
2
|
+
export { resolveFilePathAbsoluteFilesystem };
|
|
3
|
+
import type { FilePathResolved } from '../../../../../../shared/page-configs/PageConfig.js';
|
|
4
|
+
declare function resolveFilePathRelativeToUserRootDir(filePathRelativeToUserRootDir: string, userRootDir: string): FilePathResolved;
|
|
5
|
+
declare function resolveFilePathAbsoluteFilesystem(filePathAbsoluteFilesystem: string, userRootDir: string): FilePathResolved;
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export { resolveFilePathRelativeToUserRootDir };
|
|
2
|
+
export { resolveFilePathAbsoluteFilesystem };
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { assert, assertPosixPath } from '../../../../utils.js';
|
|
5
|
+
function resolveFilePathRelativeToUserRootDir(filePathRelativeToUserRootDir, userRootDir) {
|
|
6
|
+
assertPosixPath(filePathRelativeToUserRootDir);
|
|
7
|
+
assertPosixPath(userRootDir);
|
|
8
|
+
const filePathAbsoluteFilesystem = path.posix.join(userRootDir, filePathRelativeToUserRootDir);
|
|
9
|
+
return getFilePathResolved(filePathRelativeToUserRootDir, filePathAbsoluteFilesystem);
|
|
10
|
+
}
|
|
11
|
+
function resolveFilePathAbsoluteFilesystem(filePathAbsoluteFilesystem, userRootDir) {
|
|
12
|
+
assertPosixPath(filePathAbsoluteFilesystem);
|
|
13
|
+
assertPosixPath(userRootDir);
|
|
14
|
+
let filePathRelativeToUserRootDir = path.posix.relative(userRootDir, filePathAbsoluteFilesystem);
|
|
15
|
+
assert(!filePathRelativeToUserRootDir.startsWith('.') && !filePathRelativeToUserRootDir.startsWith('/'));
|
|
16
|
+
filePathRelativeToUserRootDir = '/' + filePathRelativeToUserRootDir;
|
|
17
|
+
return getFilePathResolved(filePathRelativeToUserRootDir, filePathAbsoluteFilesystem);
|
|
18
|
+
}
|
|
19
|
+
function getFilePathResolved(filePathRelativeToUserRootDir, filePathAbsoluteFilesystem) {
|
|
20
|
+
return {
|
|
21
|
+
filePathRelativeToUserRootDir,
|
|
22
|
+
filePathAbsoluteVite: filePathRelativeToUserRootDir,
|
|
23
|
+
filePathAbsoluteFilesystem,
|
|
24
|
+
filePathToShowToUser: filePathRelativeToUserRootDir,
|
|
25
|
+
importPathAbsolute: null
|
|
26
|
+
};
|
|
27
|
+
}
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { resolveImportPath };
|
|
|
3
3
|
export { assertImportPath };
|
|
4
4
|
export { clearFilesEnvMap };
|
|
5
5
|
import type { ConfigEnvInternal, DefinedAtFileFullInfo, FilePathResolved } from '../../../../../../shared/page-configs/PageConfig.js';
|
|
6
|
-
import { type ImportData } from './
|
|
6
|
+
import { type ImportData } from './transformFileImports.js';
|
|
7
7
|
declare function resolveImport(configValue: unknown, importerFilePath: FilePathResolved, userRootDir: string, configEnv: ConfigEnvInternal, configName: string): null | (DefinedAtFileFullInfo & {
|
|
8
8
|
fileExportName: string;
|
|
9
9
|
});
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js
CHANGED
|
@@ -4,7 +4,7 @@ export { assertImportPath };
|
|
|
4
4
|
export { clearFilesEnvMap };
|
|
5
5
|
import pc from '@brillout/picocolors';
|
|
6
6
|
import { assert, assertPosixPath, assertUsage, deepEqual, requireResolve } from '../../../../utils.js';
|
|
7
|
-
import { parseImportData } from './
|
|
7
|
+
import { parseImportData } from './transformFileImports.js';
|
|
8
8
|
import path from 'path';
|
|
9
9
|
const filesEnvMap = new Map();
|
|
10
10
|
function resolveImport(configValue, importerFilePath, userRootDir, configEnv, configName) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { transformFileImports };
|
|
2
2
|
export { parseImportData };
|
|
3
3
|
export { isImportData };
|
|
4
4
|
export type { FileImport };
|
|
@@ -8,7 +8,7 @@ type FileImport = {
|
|
|
8
8
|
importString: string;
|
|
9
9
|
importLocalName: string;
|
|
10
10
|
};
|
|
11
|
-
declare function
|
|
11
|
+
declare function transformFileImports(code: string, filePathToShowToUser2: string, skipWarnings?: true): {
|
|
12
12
|
noTransformation: true;
|
|
13
13
|
} | {
|
|
14
14
|
noTransformation: false;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { transformFileImports };
|
|
2
2
|
export { parseImportData };
|
|
3
3
|
export { isImportData };
|
|
4
4
|
// Playground: https://github.com/brillout/acorn-playground
|
|
@@ -7,8 +7,8 @@ export { isImportData };
|
|
|
7
7
|
import { parse } from 'acorn';
|
|
8
8
|
import { assert, assertUsage, assertWarning, styleFileRE } from '../../../../utils.js';
|
|
9
9
|
import pc from '@brillout/picocolors';
|
|
10
|
-
function
|
|
11
|
-
// For ./
|
|
10
|
+
function transformFileImports(code, filePathToShowToUser2,
|
|
11
|
+
// For ./transformFileImports.spec.ts
|
|
12
12
|
skipWarnings) {
|
|
13
13
|
const spliceOperations = [];
|
|
14
14
|
const fileImportsTransformed = [];
|
|
@@ -23,8 +23,8 @@ skipWarnings) {
|
|
|
23
23
|
return;
|
|
24
24
|
const importPath = node.source.value;
|
|
25
25
|
assert(typeof importPath === 'string');
|
|
26
|
-
// - This doesn't work. To make it work we would need to run esbuild twice: esbuild for TypeScript to JavaScript =>
|
|
27
|
-
// - Or we use an esbuild plugin to apply
|
|
26
|
+
// - This doesn't work. To make it work we would need to run esbuild twice: esbuild for TypeScript to JavaScript => transformFileImports() => esbuild for bundling.
|
|
27
|
+
// - Or we use an esbuild plugin to apply transformFileImports(). Maybe we can completely skip the need for acorn?
|
|
28
28
|
// - ?real breaks TypeScript, and TypeScript isn't working on supporting query params: https://github.com/microsoft/TypeScript/issues/10988#issuecomment-867135453
|
|
29
29
|
// - Import attributes would be the best.
|
|
30
30
|
// - But it only works with Node.js >=21: https://nodejs.org/api/esm.html#import-attributes
|
|
@@ -32,7 +32,7 @@ skipWarnings) {
|
|
|
32
32
|
// - It works well with TypeScript: it doesn't complain upon `with { type: 'unknown-to-typescript' }` and go-to-definition & types are preserved: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-3.html#import-attributes
|
|
33
33
|
// - Esbuid seems to support it: https://esbuild.github.io/plugins/#on-load-arguments:~:text=This%20contains%20a%20map%20of%20the%20import%20attributes%20that
|
|
34
34
|
// - acorn supports it over an acorn plugin: https://github.com/acornjs/acorn/issues/983
|
|
35
|
-
// - Maybe we can use an esbuild plugin instead of acorn to apply
|
|
35
|
+
// - Maybe we can use an esbuild plugin instead of acorn to apply transformFileImports()?
|
|
36
36
|
// - Using a magic comment `// @vike-real-import` is tricky:
|
|
37
37
|
// - Esbuild removes comments: https://github.com/evanw/esbuild/issues/1439#issuecomment-877656182
|
|
38
38
|
// - Using source maps to track these magic comments is brittle (source maps can easily break)
|
|
@@ -4,7 +4,7 @@ export { getConfigExecutionErrorIntroMsg };
|
|
|
4
4
|
export { isTmpFile };
|
|
5
5
|
import 'source-map-support/register.js';
|
|
6
6
|
import type { FilePathResolved } from '../../../../../../shared/page-configs/PageConfig.js';
|
|
7
|
-
declare function transpileAndExecuteFile(filePath: FilePathResolved,
|
|
7
|
+
declare function transpileAndExecuteFile(filePath: FilePathResolved, transformImports: boolean, userRootDir: string, doNotTranspile?: boolean): Promise<{
|
|
8
8
|
fileExports: Record<string, unknown>;
|
|
9
9
|
}>;
|
|
10
10
|
declare function getConfigBuildErrorFormatted(err: unknown): null | string;
|
|
@@ -8,13 +8,14 @@ import path from 'path';
|
|
|
8
8
|
import pc from '@brillout/picocolors';
|
|
9
9
|
import { import_ } from '@brillout/import';
|
|
10
10
|
import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, unique, assertWarning, isObject, toPosixPath } from '../../../../utils.js';
|
|
11
|
-
import { isImportData,
|
|
11
|
+
import { isImportData, transformFileImports } from './transformFileImports.js';
|
|
12
12
|
import { vikeConfigDependencies } from '../getVikeConfig.js';
|
|
13
13
|
import 'source-map-support/register.js';
|
|
14
14
|
import { getConfigFileExport } from '../getConfigFileExport.js';
|
|
15
15
|
assertIsNotProductionRuntime();
|
|
16
|
-
async function transpileAndExecuteFile(filePath,
|
|
17
|
-
if (
|
|
16
|
+
async function transpileAndExecuteFile(filePath, transformImports, userRootDir, doNotTranspile = false) {
|
|
17
|
+
if (doNotTranspile) {
|
|
18
|
+
assert(!transformImports);
|
|
18
19
|
const fileExports = await executeFile(filePath.filePathAbsoluteFilesystem, filePath);
|
|
19
20
|
if (isHeaderFile(filePath.filePathAbsoluteFilesystem)) {
|
|
20
21
|
const filePathToShowToUser2 = getFilePathToShowToUser2(filePath);
|
|
@@ -23,21 +24,20 @@ async function transpileAndExecuteFile(filePath, isValueFile, userRootDir, isCon
|
|
|
23
24
|
return { fileExports };
|
|
24
25
|
}
|
|
25
26
|
else {
|
|
26
|
-
const { code, fileImportsTransformed } = await transpileFile(filePath,
|
|
27
|
-
const fileExports = await executeTranspiledFile(filePath, code, fileImportsTransformed
|
|
27
|
+
const { code, fileImportsTransformed } = await transpileFile(filePath, transformImports, userRootDir);
|
|
28
|
+
const fileExports = await executeTranspiledFile(filePath, code, fileImportsTransformed);
|
|
28
29
|
return { fileExports };
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
|
-
async function transpileFile(filePath,
|
|
32
|
+
async function transpileFile(filePath, transformImports, userRootDir) {
|
|
32
33
|
const { filePathAbsoluteFilesystem } = filePath;
|
|
33
34
|
const filePathToShowToUser2 = getFilePathToShowToUser2(filePath);
|
|
34
35
|
assertPosixPath(filePathAbsoluteFilesystem);
|
|
35
36
|
vikeConfigDependencies.add(filePathAbsoluteFilesystem);
|
|
36
|
-
|
|
37
|
-
let code = await transpileWithEsbuild(filePath, userRootDir, importsAreTransformed, isValueFile);
|
|
37
|
+
let code = await transpileWithEsbuild(filePath, userRootDir, transformImports);
|
|
38
38
|
let fileImportsTransformed = null;
|
|
39
|
-
if (
|
|
40
|
-
const res =
|
|
39
|
+
if (transformImports) {
|
|
40
|
+
const res = transformFileImports_(code, filePath);
|
|
41
41
|
if (res) {
|
|
42
42
|
code = res.code;
|
|
43
43
|
fileImportsTransformed = res.fileImportsTransformed;
|
|
@@ -45,21 +45,16 @@ async function transpileFile(filePath, isValueFile, userRootDir) {
|
|
|
45
45
|
}
|
|
46
46
|
else {
|
|
47
47
|
if (isHeaderFile(filePathAbsoluteFilesystem)) {
|
|
48
|
-
|
|
49
|
-
assertWarning(false, `${filePathToShowToUser2} is a JavaScript header file (.h.js), but JavaScript header files only apply to +config.h.js, see https://vike.dev/header-file`, { onlyOnce: true });
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
assert(false);
|
|
53
|
-
}
|
|
48
|
+
assertWarning(false, `${filePathToShowToUser2} is a JavaScript header file (.h.js), but JavaScript header files only apply to +config.h.js, see https://vike.dev/header-file`, { onlyOnce: true });
|
|
54
49
|
}
|
|
55
50
|
}
|
|
56
51
|
return { code, fileImportsTransformed };
|
|
57
52
|
}
|
|
58
|
-
function
|
|
53
|
+
function transformFileImports_(codeOriginal, filePath) {
|
|
59
54
|
const { filePathAbsoluteFilesystem } = filePath;
|
|
60
55
|
const filePathToShowToUser2 = getFilePathToShowToUser2(filePath);
|
|
61
56
|
// Replace import statements with import strings
|
|
62
|
-
const res =
|
|
57
|
+
const res = transformFileImports(codeOriginal, filePathToShowToUser2);
|
|
63
58
|
if (res.noTransformation) {
|
|
64
59
|
return null;
|
|
65
60
|
}
|
|
@@ -72,8 +67,7 @@ function transformImports_(codeOriginal, filePath) {
|
|
|
72
67
|
}
|
|
73
68
|
return { code, fileImportsTransformed };
|
|
74
69
|
}
|
|
75
|
-
async function transpileWithEsbuild(filePath, userRootDir,
|
|
76
|
-
const isConfigFile = !isValueFile;
|
|
70
|
+
async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
77
71
|
const entryFilePath = filePath.filePathAbsoluteFilesystem;
|
|
78
72
|
const entryFileDir = path.posix.dirname(entryFilePath);
|
|
79
73
|
const options = {
|
|
@@ -94,12 +88,12 @@ async function transpileWithEsbuild(filePath, userRootDir, importsAreTransformed
|
|
|
94
88
|
// Esbuild still sometimes removes unused imports because of TypeScript: https://github.com/evanw/esbuild/issues/3034
|
|
95
89
|
treeShaking: false,
|
|
96
90
|
minify: false,
|
|
97
|
-
metafile:
|
|
91
|
+
metafile: !transformImports,
|
|
98
92
|
// We cannot bundle imports that are meant to be transformed
|
|
99
|
-
bundle: !
|
|
93
|
+
bundle: !transformImports
|
|
100
94
|
};
|
|
101
95
|
// Track dependencies
|
|
102
|
-
if (
|
|
96
|
+
if (!transformImports) {
|
|
103
97
|
options.packages = 'external';
|
|
104
98
|
options.plugins = [
|
|
105
99
|
{
|
|
@@ -134,7 +128,7 @@ async function transpileWithEsbuild(filePath, userRootDir, importsAreTransformed
|
|
|
134
128
|
throw err;
|
|
135
129
|
}
|
|
136
130
|
// Track dependencies
|
|
137
|
-
if (
|
|
131
|
+
if (!transformImports) {
|
|
138
132
|
assert(result.metafile);
|
|
139
133
|
Object.keys(result.metafile.inputs).forEach((filePathRelative) => {
|
|
140
134
|
filePathRelative = toPosixPath(filePathRelative);
|
|
@@ -147,7 +141,7 @@ async function transpileWithEsbuild(filePath, userRootDir, importsAreTransformed
|
|
|
147
141
|
assert(typeof code === 'string');
|
|
148
142
|
return code;
|
|
149
143
|
}
|
|
150
|
-
async function executeTranspiledFile(filePath, code, fileImportsTransformed
|
|
144
|
+
async function executeTranspiledFile(filePath, code, fileImportsTransformed) {
|
|
151
145
|
const { filePathAbsoluteFilesystem, filePathRelativeToUserRootDir } = filePath;
|
|
152
146
|
// Alternative to using a temporary file: https://github.com/vitejs/vite/pull/13269
|
|
153
147
|
// - But seems to break source maps, so I don't think it's worth it
|
|
@@ -161,7 +155,7 @@ async function executeTranspiledFile(filePath, code, fileImportsTransformed, isV
|
|
|
161
155
|
finally {
|
|
162
156
|
clean();
|
|
163
157
|
}
|
|
164
|
-
if (fileImportsTransformed
|
|
158
|
+
if (fileImportsTransformed) {
|
|
165
159
|
assert(filePathRelativeToUserRootDir !== undefined);
|
|
166
160
|
const filePathToShowToUser2 = getFilePathToShowToUser2(filePath);
|
|
167
161
|
assertImportsAreReExported(fileImportsTransformed, fileExports, filePathToShowToUser2);
|
|
@@ -5,8 +5,10 @@ export { isVikeConfigFile };
|
|
|
5
5
|
export type { InterfaceValueFile };
|
|
6
6
|
import type { PageConfigGlobalBuildTime, PageConfigBuildTime, FilePathResolved } from '../../../../../shared/page-configs/PageConfig.js';
|
|
7
7
|
import type { ExtensionResolved } from '../../../../../shared/ConfigVike.js';
|
|
8
|
+
import { type LocationId } from './getVikeConfig/filesystemRouting.js';
|
|
8
9
|
import type { ResolvedConfig } from 'vite';
|
|
9
10
|
type InterfaceFileCommons = {
|
|
11
|
+
locationId: LocationId;
|
|
10
12
|
filePath: FilePathResolved;
|
|
11
13
|
fileExportsByConfigName: Record<ConfigName, {
|
|
12
14
|
configValue?: unknown;
|