vike 0.4.150 → 0.4.151-commit-19bc995
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 +4 -4
- package/dist/cjs/node/plugin/plugins/assertFileEnv.js +107 -0
- package/dist/cjs/node/plugin/plugins/autoFullBuild.js +3 -2
- package/dist/cjs/node/plugin/plugins/baseUrls.js +2 -2
- package/dist/cjs/node/plugin/plugins/buildConfig.js +17 -36
- package/dist/cjs/node/plugin/plugins/commonConfig.js +1 -1
- package/dist/cjs/node/plugin/plugins/config/resolveExtensions.js +1 -1
- package/dist/cjs/node/plugin/plugins/config/stemUtils.js +1 -1
- package/dist/cjs/node/plugin/plugins/devConfig/determineFsAllowList.js +1 -1
- package/dist/cjs/node/plugin/plugins/importBuild/getVikeManifest.js +38 -0
- package/dist/cjs/node/plugin/plugins/importBuild/index.js +57 -19
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +10 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +46 -28
- package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errSwc.js +5 -5
- package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errSwcBig.js +4 -4
- package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errVueCss.js +7 -7
- package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errVueHtml.js +2 -2
- package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errVueJavascript.js +3 -3
- package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +1 -1
- package/dist/cjs/node/plugin/shared/loggerVite.js +1 -1
- package/dist/cjs/node/plugin/utils.js +1 -0
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +2 -0
- package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +2 -1
- package/dist/cjs/node/runtime/index-deprecated.js +3 -2
- package/dist/cjs/node/runtime/index.js +3 -2
- package/dist/cjs/node/runtime/renderPage/createHttpResponseObject/getCacheControl.js +20 -0
- package/dist/cjs/node/runtime/renderPage/createHttpResponseObject.js +8 -1
- package/dist/cjs/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +33 -0
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +1 -1
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +5 -5
- package/dist/cjs/node/runtime/renderPage.js +21 -9
- package/dist/cjs/shared/getPageFiles/getExports.js +1 -1
- package/dist/cjs/shared/route/resolveRedirects.js +3 -11
- package/dist/cjs/shared/route/resolveUrlPathname.js +48 -0
- package/dist/cjs/utils/debug.js +35 -21
- package/dist/cjs/utils/getDependencyPackageJson.js +1 -1
- package/dist/cjs/utils/getFilePathAbsolute.js +1 -1
- package/dist/cjs/utils/getOutDirs.js +11 -1
- package/dist/cjs/utils/injectRollupInputs.js +29 -0
- package/dist/cjs/utils/isPlainObject.js +1 -1
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/cjs/utils/requireResolve.js +1 -1
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +105 -66
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +1 -1
- package/dist/esm/node/plugin/index.js +4 -4
- package/dist/esm/node/plugin/plugins/assertFileEnv.d.ts +3 -0
- package/dist/esm/node/plugin/plugins/assertFileEnv.js +101 -0
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +3 -2
- package/dist/esm/node/plugin/plugins/baseUrls.js +2 -2
- package/dist/esm/node/plugin/plugins/buildConfig.js +17 -36
- package/dist/esm/node/plugin/plugins/commonConfig.js +1 -1
- package/dist/esm/node/plugin/plugins/config/resolveExtensions.js +1 -1
- package/dist/esm/node/plugin/plugins/config/stemUtils.js +1 -1
- package/dist/esm/node/plugin/plugins/devConfig/determineFsAllowList.js +1 -1
- package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.d.ts +5 -0
- package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.js +32 -0
- package/dist/esm/node/plugin/plugins/importBuild/index.js +59 -21
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/debug.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +10 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +47 -29
- package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errSwc.js +5 -5
- package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errSwcBig.js +4 -4
- package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errVueCss.js +7 -7
- package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errVueHtml.js +2 -2
- package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errVueJavascript.js +3 -3
- package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +1 -1
- package/dist/esm/node/plugin/shared/loggerVite.js +1 -1
- package/dist/esm/node/plugin/utils.d.ts +1 -0
- package/dist/esm/node/plugin/utils.js +1 -0
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +2 -0
- package/dist/esm/node/runtime/html/serializePageContextClientSide.js +2 -1
- package/dist/esm/node/runtime/index-deprecated.js +3 -2
- package/dist/esm/node/runtime/index.js +3 -2
- package/dist/esm/node/runtime/renderPage/createHttpResponseObject/getCacheControl.d.ts +3 -0
- package/dist/esm/node/runtime/renderPage/createHttpResponseObject/getCacheControl.js +17 -0
- package/dist/esm/node/runtime/renderPage/createHttpResponseObject.js +8 -1
- package/dist/esm/node/runtime/renderPage/{executeOnBeforeRenderHook.d.ts → executeOnBeforeRenderAndDataHooks.d.ts} +2 -2
- package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +30 -0
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +1 -1
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +5 -5
- package/dist/esm/node/runtime/renderPage.js +22 -10
- package/dist/esm/shared/VikeNamespace.d.ts +5 -1
- package/dist/esm/shared/getPageFiles/getExports.js +1 -1
- package/dist/esm/shared/page-configs/Config/PageContextConfig.d.ts +4 -4
- package/dist/esm/shared/page-configs/Config/helpers.d.ts +2 -2
- package/dist/esm/shared/page-configs/Config.d.ts +33 -7
- package/dist/esm/shared/route/resolveRedirects.js +3 -11
- package/dist/esm/shared/route/resolveUrlPathname.d.ts +12 -0
- package/dist/esm/shared/route/resolveUrlPathname.js +45 -0
- package/dist/esm/shared/types.d.ts +5 -0
- package/dist/esm/types/index.d.ts +1 -1
- package/dist/esm/utils/debug.d.ts +4 -4
- package/dist/esm/utils/debug.js +35 -21
- package/dist/esm/utils/debugGlob.d.ts +1 -1
- package/dist/esm/utils/getDependencyPackageJson.js +1 -1
- package/dist/esm/utils/getFilePathAbsolute.js +1 -1
- package/dist/esm/utils/getOutDirs.js +11 -1
- package/dist/esm/utils/injectRollupInputs.d.ts +7 -0
- package/dist/esm/utils/injectRollupInputs.js +26 -0
- package/dist/esm/utils/isPlainObject.js +1 -1
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/dist/esm/utils/requireResolve.js +1 -1
- package/package.json +38 -19
- package/dist/cjs/node/plugin/plugins/manifest.js +0 -59
- package/dist/cjs/node/runtime/renderPage/executeOnBeforeRenderHook.js +0 -23
- package/dist/esm/node/plugin/plugins/manifest.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/manifest.js +0 -53
- package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderHook.js +0 -20
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
export { assertFileEnv };
|
|
2
|
+
import { assert, assertUsage, assertWarning, capitalizeFirstLetter, getFilePathRelativeToUserRootDir } from '../utils.js';
|
|
3
|
+
import { extractAssetsRE } from './extractAssetsPlugin.js';
|
|
4
|
+
import { extractExportNamesRE } from './extractExportNamesPlugin.js';
|
|
5
|
+
import pc from '@brillout/picocolors';
|
|
6
|
+
function assertFileEnv() {
|
|
7
|
+
let config;
|
|
8
|
+
let isDev = false;
|
|
9
|
+
return {
|
|
10
|
+
name: 'vike:assertFileEnv',
|
|
11
|
+
// - We need to set `enforce: 'pre'` because, otherwise, the resolvedId() hook of Vite's internal plugin `vite:resolve` is called before and it doesn't seem to call `this.resolve()` which means that the resolveId() hook below is never called.
|
|
12
|
+
// - Vite's `vite:resolve` plugin: https://github.com/vitejs/vite/blob/d649daba7682791178b711d9a3e44a6b5d00990c/packages/vite/src/node/plugins/resolve.ts#L105
|
|
13
|
+
// - It's actually a good thing if the resolveId() hook below is the first one to be called because it doesn't actually resolve any ID, so all other resolveId() hooks will be called as normal. And with `this.resolve()` we get the information we want from all other resolvedId() hooks.
|
|
14
|
+
// - Path aliases are already resolved, even when using `enforce: 'pre'`. For example:
|
|
15
|
+
// ```js
|
|
16
|
+
// // /pages/index/+Page.tsx
|
|
17
|
+
//
|
|
18
|
+
// // The value of `source` is `/home/rom/code/vike/examples/path-aliases/components/Counter` (instead of `#root/components/Counter`)
|
|
19
|
+
// // The value of `importer` is `/home/rom/code/vike/examples/path-aliases/pages/index/+Page.tsx`
|
|
20
|
+
// import { Counter } from '#root/components/Counter'
|
|
21
|
+
// ```
|
|
22
|
+
enforce: 'pre',
|
|
23
|
+
resolveId: {
|
|
24
|
+
/* I don't know why, but path aliases aren't resolved anymore when setting `order: 'pre'`. (In principle, I'd assume that `this.resolve()` would resolve the alias but it doesn't.)
|
|
25
|
+
order: 'pre',
|
|
26
|
+
*/
|
|
27
|
+
async handler(source, importer, options) {
|
|
28
|
+
// TODO/v1-release: remove
|
|
29
|
+
if (extractAssetsRE.test(source) || extractExportNamesRE.test(source))
|
|
30
|
+
return;
|
|
31
|
+
// Seems like Vite is doing some funky stuff here.
|
|
32
|
+
if (importer?.endsWith('.html'))
|
|
33
|
+
return;
|
|
34
|
+
const resolved = await this.resolve(source, importer, {
|
|
35
|
+
// Needed for old Vite plugins: https://vitejs.dev/guide/migration#rollup-4:~:text=For%20Vite%20plugins%2C%20this.resolve%20skipSelf%20option%20is%20now%20true%20by%20default.
|
|
36
|
+
skipSelf: true,
|
|
37
|
+
...options
|
|
38
|
+
});
|
|
39
|
+
// resolved is null when import path is erroneous and doesn't actually point to a file
|
|
40
|
+
if (!resolved)
|
|
41
|
+
return;
|
|
42
|
+
const modulePath = resolved.id.split('?')[0];
|
|
43
|
+
// `.server.js` and `.client.js` should only apply to user files
|
|
44
|
+
if (modulePath.includes('/node_modules/'))
|
|
45
|
+
return;
|
|
46
|
+
// TODO/v1-release: remove
|
|
47
|
+
if (modulePath.endsWith('.css'))
|
|
48
|
+
return;
|
|
49
|
+
const isServerSide = options?.ssr;
|
|
50
|
+
const envActual = isServerSide ? 'server' : 'client';
|
|
51
|
+
const envExpect = isServerSide ? 'client' : 'server';
|
|
52
|
+
const suffix = `.${envExpect}.`;
|
|
53
|
+
// Everything nonimal
|
|
54
|
+
if (!modulePath.includes(suffix))
|
|
55
|
+
return;
|
|
56
|
+
// Show error message
|
|
57
|
+
let errMsg;
|
|
58
|
+
let modulePathPretty = getFilePathRelativeToUserRootDir(modulePath, config.root);
|
|
59
|
+
modulePathPretty = modulePathPretty.replaceAll(suffix, pc.bold(suffix));
|
|
60
|
+
errMsg = `${capitalizeFirstLetter(envExpect)}-only module ${modulePathPretty} (https://vike.dev/file-env) imported on the ${envActual}-side`;
|
|
61
|
+
if (importer &&
|
|
62
|
+
// Don't show Vike's virtual modules that import the entry plus files such as /pages/about/+Page.js
|
|
63
|
+
!importer.includes('virtual:vike:') &&
|
|
64
|
+
// I don't know why and who sets importer to '<stdin>' (I guess Vite?)
|
|
65
|
+
importer !== '<stdin>') {
|
|
66
|
+
const importerPath = getFilePathRelativeToUserRootDir(importer.split('?')[0], config.root);
|
|
67
|
+
errMsg += ` by ${importerPath}`;
|
|
68
|
+
}
|
|
69
|
+
if (isDev) {
|
|
70
|
+
errMsg += ' (building your app for production will be prevented and an error will be thrown)';
|
|
71
|
+
}
|
|
72
|
+
errMsg += '.';
|
|
73
|
+
if (isDev) {
|
|
74
|
+
assertWarning(false, errMsg, { onlyOnce: true });
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
assertUsage(false, errMsg);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
configResolved(config_) {
|
|
82
|
+
config = config_;
|
|
83
|
+
},
|
|
84
|
+
configureServer() {
|
|
85
|
+
isDev = true;
|
|
86
|
+
},
|
|
87
|
+
// Ensure this plugin works
|
|
88
|
+
transform(_code, id, options) {
|
|
89
|
+
if (isDev)
|
|
90
|
+
return;
|
|
91
|
+
// TODO/v1-release: remove
|
|
92
|
+
if (extractAssetsRE.test(id) || extractExportNamesRE.test(id))
|
|
93
|
+
return;
|
|
94
|
+
if (id.split('?')[0].endsWith('.css'))
|
|
95
|
+
return;
|
|
96
|
+
const isServerSide = options?.ssr;
|
|
97
|
+
const envWrong = isServerSide ? 'client' : 'server';
|
|
98
|
+
assert(!id.includes(`.${envWrong}.`));
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
@@ -57,9 +57,10 @@ async function triggerFullBuild(config, configVike, bundle) {
|
|
|
57
57
|
return; // already triggered
|
|
58
58
|
if (isDisabled(configVike))
|
|
59
59
|
return;
|
|
60
|
+
/* Is this @vitejs/plugin-legacy workaround still needed? Should we re-implement it?
|
|
60
61
|
// vike.json missing => it isn't a `$ vite build` call (e.g. @vitejs/plugin-legacy calls Vite's build() API) => skip
|
|
61
|
-
if (!bundle['vike.json'])
|
|
62
|
-
|
|
62
|
+
if (!bundle['vike.json']) return
|
|
63
|
+
*/
|
|
63
64
|
const configFromCli = !isViteCliCall() ? null : getViteConfigFromCli();
|
|
64
65
|
const configInline = {
|
|
65
66
|
...configFromCli,
|
|
@@ -17,11 +17,11 @@ function baseUrls(configVike) {
|
|
|
17
17
|
process.env.BASE_ASSETS = baseAssets;
|
|
18
18
|
return {
|
|
19
19
|
envPrefix: [
|
|
20
|
-
'VITE_',
|
|
20
|
+
'VITE_', // Vite doesn't seem to merge in its default, see https://github.com/vikejs/vike/issues/554
|
|
21
21
|
'BASE_SERVER',
|
|
22
22
|
'BASE_ASSETS'
|
|
23
23
|
],
|
|
24
|
-
base: baseAssets,
|
|
24
|
+
base: baseAssets, // Make Vite inject baseAssets to imports e.g. `import logoUrl from './logo.svg.js'`
|
|
25
25
|
_baseOriginal: config.base ?? '/__UNSET__' // Vite resolves `_baseOriginal: null` to `undefined`
|
|
26
26
|
};
|
|
27
27
|
},
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
export { buildConfig };
|
|
2
2
|
export { assertRollupInput };
|
|
3
3
|
export { analyzeClientEntries };
|
|
4
|
-
import { assert, resolveOutDir,
|
|
5
|
-
import { virtualFileIdImportUserCodeServer } from '../../shared/virtual-files/virtualFileImportUserCode.js';
|
|
4
|
+
import { assert, resolveOutDir, viteIsSSR, getFilePathAbsolute, addOnBeforeLogHook, removeFileExtention, unique, assertPosixPath, assertUsage, injectRollupInputs, normalizeRollupInput } from '../utils.js';
|
|
6
5
|
import { getVikeConfig } from './importUserCode/v1-design/getVikeConfig.js';
|
|
7
6
|
import { getConfigValue } from '../../../shared/page-configs/helpers.js';
|
|
8
7
|
import { findPageFiles } from '../shared/findPageFiles.js';
|
|
@@ -13,7 +12,7 @@ import { createRequire } from 'module';
|
|
|
13
12
|
import { getClientEntryFilePath } from '../../shared/getClientEntryFilePath.js';
|
|
14
13
|
import fs from 'fs/promises';
|
|
15
14
|
import path from 'path';
|
|
16
|
-
// @ts-ignore
|
|
15
|
+
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
17
16
|
const importMetaUrl = import.meta.url;
|
|
18
17
|
const require_ = createRequire(importMetaUrl);
|
|
19
18
|
const manifestTempFile = '_temp_manifest.json';
|
|
@@ -27,14 +26,9 @@ function buildConfig() {
|
|
|
27
26
|
order: 'post',
|
|
28
27
|
async handler(config) {
|
|
29
28
|
assertRollupInput(config);
|
|
30
|
-
const userInputs = normalizeRollupInput(config.build.rollupOptions.input);
|
|
31
29
|
const entries = await getEntries(config);
|
|
32
30
|
assert(Object.keys(entries).length > 0);
|
|
33
|
-
|
|
34
|
-
...entries,
|
|
35
|
-
...userInputs
|
|
36
|
-
};
|
|
37
|
-
config.build.rollupOptions.input = input;
|
|
31
|
+
config.build.rollupOptions.input = injectRollupInputs(entries, config);
|
|
38
32
|
addLogHook();
|
|
39
33
|
}
|
|
40
34
|
},
|
|
@@ -72,12 +66,12 @@ async function getEntries(config) {
|
|
|
72
66
|
const { pageConfigs } = await getVikeConfig(config, false);
|
|
73
67
|
assertUsage(Object.keys(pageFileEntries).length !== 0 || pageConfigs.length !== 0, 'At least one page should be defined, see https://vike.dev/add');
|
|
74
68
|
if (viteIsSSR(config)) {
|
|
75
|
-
const
|
|
69
|
+
const pageEntries = getPageEntries(pageConfigs);
|
|
76
70
|
const entries = {
|
|
77
|
-
|
|
78
|
-
importBuild: resolve('dist/esm/node/importBuild.js'),
|
|
71
|
+
// importBuild: resolve('dist/esm/node/importBuild.js'), // TODO/next-major-release: remove
|
|
79
72
|
...pageFileEntries,
|
|
80
|
-
|
|
73
|
+
// Ensure Rollup generates a bundle per page: https://github.com/vikejs/vike/issues/349#issuecomment-1166247275
|
|
74
|
+
...pageEntries
|
|
81
75
|
};
|
|
82
76
|
return entries;
|
|
83
77
|
}
|
|
@@ -102,6 +96,14 @@ async function getEntries(config) {
|
|
|
102
96
|
return entries;
|
|
103
97
|
}
|
|
104
98
|
}
|
|
99
|
+
function getPageEntries(pageConfigs) {
|
|
100
|
+
const pageEntries = {};
|
|
101
|
+
pageConfigs.forEach((pageConfig) => {
|
|
102
|
+
const { entryName, entryTarget } = getEntryFromPageConfig(pageConfig, false);
|
|
103
|
+
pageEntries[entryName] = entryTarget;
|
|
104
|
+
});
|
|
105
|
+
return pageEntries;
|
|
106
|
+
}
|
|
105
107
|
function analyzeClientEntries(pageConfigs, config) {
|
|
106
108
|
let hasClientRouting = false;
|
|
107
109
|
let hasServerRouting = false;
|
|
@@ -116,6 +118,7 @@ function analyzeClientEntries(pageConfigs, config) {
|
|
|
116
118
|
hasServerRouting = true;
|
|
117
119
|
}
|
|
118
120
|
{
|
|
121
|
+
// Ensure Rollup generates a bundle per page: https://github.com/vikejs/vike/issues/349#issuecomment-1166247275
|
|
119
122
|
const { entryName, entryTarget } = getEntryFromPageConfig(pageConfig, true);
|
|
120
123
|
clientEntries[entryName] = entryTarget;
|
|
121
124
|
}
|
|
@@ -133,14 +136,6 @@ function analyzeClientEntries(pageConfigs, config) {
|
|
|
133
136
|
});
|
|
134
137
|
return { hasClientRouting, hasServerRouting, clientEntries };
|
|
135
138
|
}
|
|
136
|
-
function analyzeServerEntries(pageConfigs) {
|
|
137
|
-
const serverEntries = {};
|
|
138
|
-
pageConfigs.forEach((pageConfig) => {
|
|
139
|
-
const { entryName, entryTarget } = getEntryFromPageConfig(pageConfig, false);
|
|
140
|
-
serverEntries[entryName] = entryTarget;
|
|
141
|
-
});
|
|
142
|
-
return serverEntries;
|
|
143
|
-
}
|
|
144
139
|
// Ensure Rollup creates entries for each page file, see https://github.com/vikejs/vike/issues/350
|
|
145
140
|
// (Otherwise the page files may be missing in the client manifest.json)
|
|
146
141
|
async function getPageFileEntries(config, includeAssetsImportedByServer) {
|
|
@@ -196,20 +191,6 @@ function resolve(filePath) {
|
|
|
196
191
|
// [RELATIVE_PATH_FROM_DIST] Current directory: node_modules/vike/dist/esm/node/plugin/plugins/
|
|
197
192
|
return require_.resolve(`../../../../../${filePath}`);
|
|
198
193
|
}
|
|
199
|
-
function normalizeRollupInput(input) {
|
|
200
|
-
if (!input) {
|
|
201
|
-
return {};
|
|
202
|
-
}
|
|
203
|
-
// Usually `input` is an oject, but the user can set it as a `string` or `string[]`
|
|
204
|
-
if (typeof input === 'string') {
|
|
205
|
-
input = [input];
|
|
206
|
-
}
|
|
207
|
-
if (Array.isArray(input)) {
|
|
208
|
-
return Object.fromEntries(input.map((input) => [input, input]));
|
|
209
|
-
}
|
|
210
|
-
assert(isObject(input));
|
|
211
|
-
return input;
|
|
212
|
-
}
|
|
213
194
|
function addLogHook() {
|
|
214
195
|
const tty = process.stdout.isTTY && !process.env.CI; // Equals https://github.com/vitejs/vite/blob/193d55c7b9cbfec5b79ebfca276d4a721e7de14d/packages/vite/src/node/plugins/reporter.ts#L27
|
|
215
196
|
if (!tty)
|
|
@@ -241,5 +222,5 @@ function assertRollupInput(config) {
|
|
|
241
222
|
const userInputs = normalizeRollupInput(config.build.rollupOptions.input);
|
|
242
223
|
const htmlInputs = Object.values(userInputs).filter((entry) => entry.endsWith('.html') || entry.endsWith('.htm'));
|
|
243
224
|
const htmlInput = htmlInputs[0];
|
|
244
|
-
assertUsage(htmlInput === undefined, `The entry ${htmlInput} of config build.rollupOptions.input is an HTML entry which is forbidden when using
|
|
225
|
+
assertUsage(htmlInput === undefined, `The entry ${htmlInput} of config build.rollupOptions.input is an HTML entry which is forbidden when using Vike, instead follow https://vike.dev/add`);
|
|
245
226
|
}
|
|
@@ -6,7 +6,7 @@ import pc from '@brillout/picocolors';
|
|
|
6
6
|
import path from 'path';
|
|
7
7
|
import { createRequire } from 'module';
|
|
8
8
|
import { assertResolveAlias } from './commonConfig/assertResolveAlias.js';
|
|
9
|
-
// @ts-ignore
|
|
9
|
+
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
10
10
|
const importMetaUrl = import.meta.url;
|
|
11
11
|
const require_ = createRequire(importMetaUrl);
|
|
12
12
|
function commonConfig() {
|
|
@@ -5,7 +5,7 @@ import fs from 'fs';
|
|
|
5
5
|
import { isValidFileType } from '../../../../shared/getPageFiles/fileTypes.js';
|
|
6
6
|
import { createRequire } from 'module';
|
|
7
7
|
import pc from '@brillout/picocolors';
|
|
8
|
-
// @ts-ignore
|
|
8
|
+
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
9
9
|
const importMetaUrl = import.meta.url;
|
|
10
10
|
const require_ = createRequire(importMetaUrl);
|
|
11
11
|
function resolveExtensions(configs, config) {
|
|
@@ -4,7 +4,7 @@ import path from 'path';
|
|
|
4
4
|
import { assert, assertUsage, assertWarning, toPosixPath, assertPosixPath, getDependencyRootDir, findUserPackageJsonPath } from '../../utils.js';
|
|
5
5
|
import { import_ } from '@brillout/import';
|
|
6
6
|
import { createRequire } from 'module';
|
|
7
|
-
// @ts-ignore
|
|
7
|
+
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
8
8
|
const importMetaUrl = import.meta.url;
|
|
9
9
|
const require_ = createRequire(importMetaUrl);
|
|
10
10
|
async function getStemPackages(userAppRootDir) {
|
|
@@ -6,7 +6,7 @@ import { assert } from '../../utils.js';
|
|
|
6
6
|
import { createRequire } from 'module';
|
|
7
7
|
import { dirname } from 'path';
|
|
8
8
|
import { fileURLToPath } from 'url';
|
|
9
|
-
// @ts-ignore
|
|
9
|
+
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
10
10
|
const importMetaUrl = import.meta.url;
|
|
11
11
|
const require_ = createRequire(importMetaUrl);
|
|
12
12
|
const __dirname_ = dirname(fileURLToPath(importMetaUrl));
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { getVikeManifest };
|
|
2
|
+
import { ResolvedConfig } from 'vite';
|
|
3
|
+
import { type PluginManifest } from '../../../shared/assertPluginManifest.js';
|
|
4
|
+
import type { ConfigVikeResolved } from '../../../../shared/ConfigVike.js';
|
|
5
|
+
declare function getVikeManifest(config: ResolvedConfig, configVike: ConfigVikeResolved): PluginManifest;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export { getVikeManifest };
|
|
2
|
+
import { projectInfo, toPosixPath, assertPosixPath, isNotNullish } from '../../utils.js';
|
|
3
|
+
import { assertPluginManifest } from '../../../shared/assertPluginManifest.js';
|
|
4
|
+
import { isUsingClientRouter } from '../extractExportNamesPlugin.js';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { getRuntimeManifest } from '../../../runtime/globalContext.js';
|
|
7
|
+
function getVikeManifest(config, configVike) {
|
|
8
|
+
const runtimeManifest = getRuntimeManifest(configVike);
|
|
9
|
+
const manifest = {
|
|
10
|
+
version: projectInfo.projectVersion,
|
|
11
|
+
usesClientRouter: isUsingClientRouter(), // TODO/v1-release: remove
|
|
12
|
+
manifestKeyMap: getManifestKeyMap(configVike, config),
|
|
13
|
+
...runtimeManifest
|
|
14
|
+
};
|
|
15
|
+
assertPluginManifest(manifest);
|
|
16
|
+
return manifest;
|
|
17
|
+
}
|
|
18
|
+
function getManifestKeyMap(configVike, config) {
|
|
19
|
+
const manifestKeyMap = {};
|
|
20
|
+
configVike.extensions
|
|
21
|
+
.map(({ pageConfigsDistFiles }) => pageConfigsDistFiles)
|
|
22
|
+
.flat()
|
|
23
|
+
.filter(isNotNullish)
|
|
24
|
+
.forEach(({ importPath, filePath }) => {
|
|
25
|
+
// Recreating https://github.com/vitejs/vite/blob/8158ece72b66307e7b607b98496891610ca70ea2/packages/vite/src/node/plugins/manifest.ts#L38
|
|
26
|
+
const filePathRelative = path.posix.relative(config.root, toPosixPath(filePath));
|
|
27
|
+
assertPosixPath(filePathRelative);
|
|
28
|
+
assertPosixPath(importPath);
|
|
29
|
+
manifestKeyMap[importPath] = filePathRelative;
|
|
30
|
+
});
|
|
31
|
+
return manifestKeyMap;
|
|
32
|
+
}
|
|
@@ -1,48 +1,86 @@
|
|
|
1
1
|
export { importBuild };
|
|
2
|
-
import { importBuild as importBuild_ } from '@brillout/vite-plugin-import-build/plugin.js';
|
|
3
|
-
import { getOutDirs, projectInfo, toPosixPath } from '../../utils.js';
|
|
2
|
+
import { importBuild as importBuild_, findImportBuildBundleEntry } from '@brillout/vite-plugin-import-build/plugin.js';
|
|
3
|
+
import { assert, getOutDirs, projectInfo, toPosixPath, viteIsSSR } from '../../utils.js';
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import { createRequire } from 'module';
|
|
6
|
-
|
|
6
|
+
import { getConfigVike } from '../../../shared/getConfigVike.js';
|
|
7
|
+
import { getVikeManifest } from './getVikeManifest.js';
|
|
8
|
+
import fs from 'fs/promises';
|
|
9
|
+
import { virtualFileIdImportUserCodeServer } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
|
|
10
|
+
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
7
11
|
const importMetaUrl = import.meta.url;
|
|
8
12
|
const require_ = createRequire(importMetaUrl);
|
|
13
|
+
const ASSETS_MAP = '__VITE_ASSETS_MAP__';
|
|
9
14
|
function importBuild() {
|
|
10
15
|
let config;
|
|
16
|
+
let configVike;
|
|
11
17
|
return [
|
|
12
18
|
{
|
|
13
19
|
name: 'vike:importBuild:config',
|
|
14
20
|
enforce: 'post',
|
|
15
|
-
configResolved(config_) {
|
|
21
|
+
async configResolved(config_) {
|
|
16
22
|
config = config_;
|
|
23
|
+
configVike = await getConfigVike(config);
|
|
24
|
+
},
|
|
25
|
+
async writeBundle(options, bundle) {
|
|
26
|
+
if (!viteIsSSR(config))
|
|
27
|
+
return;
|
|
28
|
+
await replace_ASSETS_MAP(options, bundle);
|
|
17
29
|
}
|
|
18
30
|
},
|
|
19
31
|
importBuild_({
|
|
20
|
-
getImporterCode: (
|
|
21
|
-
|
|
22
|
-
return getImporterCode(config, pageFilesEntry);
|
|
32
|
+
getImporterCode: () => {
|
|
33
|
+
return getEntryCode(config, configVike);
|
|
23
34
|
},
|
|
24
35
|
libraryName: projectInfo.projectName
|
|
25
36
|
})
|
|
26
37
|
];
|
|
27
38
|
}
|
|
28
|
-
function
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
require_.resolve(`../../../../../../dist/esm/node/runtime/globalContext/loadImportBuild.js`));
|
|
32
|
-
const { outDirServer } = getOutDirs(config);
|
|
33
|
-
const filePathRelative = path.posix.relative(outDirServer, filePathAbsolute);
|
|
34
|
-
// The only reason we went for using CJS require() instead of ESM import() is because import() doesn't support .json files
|
|
39
|
+
function getEntryCode(config, configVike) {
|
|
40
|
+
const importPath = getImportPath(config);
|
|
41
|
+
const vikeManifest = getVikeManifest(config, configVike);
|
|
35
42
|
const importerCode = [
|
|
36
|
-
|
|
37
|
-
`
|
|
43
|
+
` import { setImportBuildGetters } from '${importPath}';`,
|
|
44
|
+
` import * as pageFiles from '${virtualFileIdImportUserCodeServer}';`,
|
|
38
45
|
' setImportBuildGetters({',
|
|
39
|
-
` pageFiles: () =>
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
46
|
+
` pageFiles: () => pageFiles,`,
|
|
47
|
+
// TODO: rename clientManifest -> assetManifest
|
|
48
|
+
` clientManifest: () => { return ${ASSETS_MAP} },`,
|
|
49
|
+
// TODO: rename pluginManifest -> vikeManifest
|
|
50
|
+
` pluginManifest: () => (${JSON.stringify(vikeManifest, null, 2)}),`,
|
|
43
51
|
' });',
|
|
44
|
-
'})()',
|
|
45
52
|
''
|
|
46
53
|
].join('\n');
|
|
47
54
|
return importerCode;
|
|
48
55
|
}
|
|
56
|
+
async function replace_ASSETS_MAP(options, bundle) {
|
|
57
|
+
const { dir } = options;
|
|
58
|
+
assert(dir);
|
|
59
|
+
// I guess importBuild won't be found in the bundle when using @vitejs/plugin-legacy
|
|
60
|
+
const importBuildEntry = findImportBuildBundleEntry(bundle);
|
|
61
|
+
const importBuildFilePath = path.join(dir, importBuildEntry.fileName);
|
|
62
|
+
const assetsJsonFilePath = path.join(dir, '..', 'assets.json');
|
|
63
|
+
const [assetsJsonString, importBuildFileContent] = await Promise.all([
|
|
64
|
+
await fs.readFile(assetsJsonFilePath, 'utf8'),
|
|
65
|
+
await fs.readFile(importBuildFilePath, 'utf8')
|
|
66
|
+
]);
|
|
67
|
+
const importBuildFileContentFixed = importBuildFileContent.replace(ASSETS_MAP, assetsJsonString);
|
|
68
|
+
assert(importBuildFileContentFixed !== importBuildFileContent);
|
|
69
|
+
await fs.writeFile(importBuildFilePath, importBuildFileContentFixed);
|
|
70
|
+
}
|
|
71
|
+
function getImportPath(config) {
|
|
72
|
+
// We resolve filePathAbsolute even if we don't use it: we use require.resolve() as an assertion that the relative path is correct
|
|
73
|
+
const filePathAbsolute = toPosixPath(
|
|
74
|
+
// [RELATIVE_PATH_FROM_DIST] Current file: node_modules/vike/dist/esm/node/plugin/plugins/importBuild/index.js
|
|
75
|
+
require_.resolve(`../../../../../../dist/esm/node/runtime/globalContext/loadImportBuild.js`));
|
|
76
|
+
if (
|
|
77
|
+
// Let's implement a new config if a user needs the import to be a relative path instead of 'vike/__internal/loadImportBuild' (AFAIK a relative path is needed only if a framework has npm package 'vike' as direct dependency instead of a peer dependency and if the user of that framework uses pnpm)
|
|
78
|
+
true) {
|
|
79
|
+
return 'vike/__internal/loadImportBuild';
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
const { outDirServer } = getOutDirs(config);
|
|
83
|
+
const filePathRelative = path.posix.relative(outDirServer, filePathAbsolute);
|
|
84
|
+
return filePathRelative;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -36,6 +36,9 @@ const configDefinitionsBuiltIn = {
|
|
|
36
36
|
guard: {
|
|
37
37
|
env: { server: true, client: 'if-client-routing' }
|
|
38
38
|
},
|
|
39
|
+
data: {
|
|
40
|
+
env: { server: true }
|
|
41
|
+
},
|
|
39
42
|
iKnowThePerformanceRisksOfAsyncRouteFunctions: {
|
|
40
43
|
env: { server: true, client: 'if-client-routing', eager: true }
|
|
41
44
|
},
|
|
@@ -76,8 +79,15 @@ const configDefinitionsBuiltIn = {
|
|
|
76
79
|
env: { client: true },
|
|
77
80
|
_computed: (configValueSources) => !isConfigSet(configValueSources, 'onBeforeRender') ? null : getConfigEnv(configValueSources, 'onBeforeRender')
|
|
78
81
|
},
|
|
82
|
+
dataEnv: {
|
|
83
|
+
env: { client: true },
|
|
84
|
+
_computed: (configValueSources) => !isConfigSet(configValueSources, 'data') ? null : getConfigEnv(configValueSources, 'data')
|
|
85
|
+
},
|
|
79
86
|
hooksTimeout: {
|
|
80
87
|
env: { server: true, client: true }
|
|
88
|
+
},
|
|
89
|
+
cacheControl: {
|
|
90
|
+
env: { server: true }
|
|
81
91
|
}
|
|
82
92
|
};
|
|
83
93
|
const configDefinitionsBuiltInGlobal = {
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
export { crawlPlusFiles };
|
|
2
|
-
import { assertPosixPath, assert, toPosixPath, assertWarning, scriptFileExtensionList, scriptFileExtensions } from '../../../../utils.js';
|
|
2
|
+
import { assertPosixPath, assert, toPosixPath, assertWarning, scriptFileExtensionList, scriptFileExtensions, getGlobalObject } from '../../../../utils.js';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import glob from 'fast-glob';
|
|
5
5
|
import { exec } from 'child_process';
|
|
6
6
|
import { promisify } from 'util';
|
|
7
7
|
const execA = promisify(exec);
|
|
8
|
+
const globalObject = getGlobalObject('crawlPlusFiles.ts', {
|
|
9
|
+
gitIsMissing: false
|
|
10
|
+
});
|
|
8
11
|
async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
|
|
9
12
|
assertPosixPath(userRootDir);
|
|
10
13
|
assertPosixPath(outDirAbsoluteFilesystem);
|
|
11
|
-
// Vike prepends userRootDir without resolving, e.g. outDirRelativeFromUserRootDir can be /home/rom/my-monorepo/my-app/../my-build/dist/ while userRootDir is /home/rom/my-monorepo/my-app/
|
|
12
|
-
assert(outDirAbsoluteFilesystem.startsWith(userRootDir));
|
|
13
14
|
let outDirRelativeFromUserRootDir = path.posix.relative(userRootDir, outDirAbsoluteFilesystem);
|
|
14
15
|
if (outDirRelativeFromUserRootDir.startsWith('../')) {
|
|
15
16
|
// config.outDir is outside of config.root => it's going to be ignored anyways
|
|
16
17
|
outDirRelativeFromUserRootDir = null;
|
|
17
18
|
}
|
|
18
19
|
assert(outDirRelativeFromUserRootDir === null || !outDirRelativeFromUserRootDir.startsWith('.'));
|
|
19
|
-
const
|
|
20
|
+
const timeBefore = new Date().getTime();
|
|
20
21
|
let files = [];
|
|
21
22
|
const res = await gitLsFiles(userRootDir, outDirRelativeFromUserRootDir);
|
|
22
23
|
if (res &&
|
|
23
|
-
// Fallback to fast-glob for users that dynamically generate plus files (
|
|
24
|
+
// Fallback to fast-glob for users that dynamically generate plus files. (Assuming all (generetad) plus files to be skipped because users usually included them in `.gitignore`.)
|
|
24
25
|
res.length > 0) {
|
|
25
26
|
files = res;
|
|
26
27
|
}
|
|
@@ -28,10 +29,11 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
|
|
|
28
29
|
files = await fastGlob(userRootDir, outDirRelativeFromUserRootDir);
|
|
29
30
|
}
|
|
30
31
|
{
|
|
31
|
-
const
|
|
32
|
+
const timeAfter = new Date().getTime();
|
|
33
|
+
const timeSpent = timeAfter - timeBefore;
|
|
32
34
|
if (isDev) {
|
|
33
|
-
// We only warn in dev, because while building it's expected to take a long time as
|
|
34
|
-
assertWarning(
|
|
35
|
+
// We only warn in dev, because while building it's expected to take a long time as crawling is competing for resources with other tasks.
|
|
36
|
+
assertWarning(timeSpent < 2 * 1000, `Crawling your user files took an unexpected long time (${timeSpent}ms). Create a new issue on Vike's GitHub.`, {
|
|
35
37
|
onlyOnce: 'slow-page-files-search'
|
|
36
38
|
});
|
|
37
39
|
}
|
|
@@ -50,37 +52,54 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
|
|
|
50
52
|
}
|
|
51
53
|
// Same as fastGlob() but using `$ git ls-files`
|
|
52
54
|
async function gitLsFiles(userRootDir, outDirRelativeFromUserRootDir) {
|
|
53
|
-
if (
|
|
55
|
+
if (globalObject.gitIsMissing)
|
|
54
56
|
return null;
|
|
57
|
+
const ignoreAsPatterns = getIgnoreAsPatterns(outDirRelativeFromUserRootDir);
|
|
58
|
+
const ignoreAsFilterFn = getIgnoreAsFilterFn(outDirRelativeFromUserRootDir);
|
|
55
59
|
const cmd = [
|
|
56
60
|
'git ls-files',
|
|
57
61
|
...scriptFileExtensionList.map((ext) => `"**/+*.${ext}"`),
|
|
58
|
-
...
|
|
62
|
+
...ignoreAsPatterns.map((pattern) => `--exclude="${pattern}"`),
|
|
59
63
|
// --others lists untracked files only (but using .gitignore because --exclude-standard)
|
|
60
64
|
// --cached adds the tracked files to the output
|
|
61
65
|
'--others --cached --exclude-standard'
|
|
62
66
|
].join(' ');
|
|
63
|
-
let files
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
let files;
|
|
68
|
+
let filesDeleted;
|
|
69
|
+
try {
|
|
70
|
+
;
|
|
71
|
+
[files, filesDeleted] = await Promise.all([
|
|
72
|
+
// Main command
|
|
73
|
+
runCmd(cmd, userRootDir),
|
|
74
|
+
// Get tracked by deleted files
|
|
75
|
+
runCmd('git ls-files --deleted', userRootDir)
|
|
76
|
+
]);
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
if (await isGitMissing(userRootDir)) {
|
|
80
|
+
globalObject.gitIsMissing = true;
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
throw err;
|
|
84
|
+
}
|
|
85
|
+
files = files
|
|
86
|
+
// We have to repeat the same exclusion logic here because the `git ls-files` option --exclude only applies to untracked files. (We use --exclude only to speed up the command.)
|
|
87
|
+
.filter(ignoreAsFilterFn)
|
|
88
|
+
.filter((file) => !filesDeleted.includes(file));
|
|
70
89
|
return files;
|
|
71
90
|
}
|
|
72
91
|
// Same as gitLsFiles() but using fast-glob
|
|
73
92
|
async function fastGlob(userRootDir, outDirRelativeFromUserRootDir) {
|
|
74
93
|
const files = await glob(`**/+*.${scriptFileExtensions}`, {
|
|
75
|
-
ignore:
|
|
94
|
+
ignore: getIgnoreAsPatterns(outDirRelativeFromUserRootDir),
|
|
76
95
|
cwd: userRootDir,
|
|
77
96
|
dot: false
|
|
78
97
|
});
|
|
79
98
|
return files;
|
|
80
99
|
}
|
|
81
100
|
// Same as getIgnoreFilter() but as glob pattern
|
|
82
|
-
function
|
|
83
|
-
const
|
|
101
|
+
function getIgnoreAsPatterns(outDirRelativeFromUserRootDir) {
|
|
102
|
+
const ignoreAsPatterns = [
|
|
84
103
|
'**/node_modules/**',
|
|
85
104
|
// Allow:
|
|
86
105
|
// ```
|
|
@@ -91,31 +110,30 @@ function getIgnorePatterns(outDirRelativeFromUserRootDir) {
|
|
|
91
110
|
];
|
|
92
111
|
if (outDirRelativeFromUserRootDir) {
|
|
93
112
|
assert(!outDirRelativeFromUserRootDir.startsWith('/'));
|
|
94
|
-
|
|
113
|
+
ignoreAsPatterns.push(`${outDirRelativeFromUserRootDir}/**`);
|
|
95
114
|
}
|
|
96
|
-
return
|
|
115
|
+
return ignoreAsPatterns;
|
|
97
116
|
}
|
|
98
117
|
// Same as getIgnorePatterns() but for Array.filter()
|
|
99
|
-
function
|
|
100
|
-
assert(!file.startsWith('/'));
|
|
118
|
+
function getIgnoreAsFilterFn(outDirRelativeFromUserRootDir) {
|
|
101
119
|
assert(outDirRelativeFromUserRootDir === null || !outDirRelativeFromUserRootDir.startsWith('/'));
|
|
102
|
-
return (!file.includes('node_modules/') &&
|
|
120
|
+
return (file) => !file.includes('node_modules/') &&
|
|
103
121
|
!file.includes('.telefunc.') &&
|
|
104
|
-
(
|
|
122
|
+
(outDirRelativeFromUserRootDir === null || !file.startsWith(`${outDirRelativeFromUserRootDir}/`));
|
|
105
123
|
}
|
|
106
124
|
// Whether Git is installed and whether userRootDir is inside a Git repository
|
|
107
|
-
async function
|
|
125
|
+
async function isGitMissing(userRootDir) {
|
|
108
126
|
let res;
|
|
109
127
|
try {
|
|
110
128
|
res = await execA('git rev-parse --is-inside-work-tree', { cwd: userRootDir });
|
|
111
129
|
}
|
|
112
130
|
catch {
|
|
113
|
-
return
|
|
131
|
+
return true;
|
|
114
132
|
}
|
|
115
133
|
const { stdout, stderr } = res;
|
|
116
134
|
assert(stderr.toString().trim() === '');
|
|
117
135
|
assert(stdout.toString().trim() === 'true');
|
|
118
|
-
return
|
|
136
|
+
return false;
|
|
119
137
|
}
|
|
120
138
|
async function runCmd(cmd, cwd) {
|
|
121
139
|
const res = await execA(cmd, { cwd });
|