vike 0.4.161 → 0.4.162
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/__internal/index.js +2 -2
- package/dist/cjs/node/plugin/index.js +0 -2
- package/dist/cjs/node/plugin/plugins/buildConfig.js +20 -20
- package/dist/cjs/node/plugin/plugins/config/index.js +2 -7
- package/dist/cjs/node/plugin/plugins/devConfig/determineFsAllowList.js +1 -8
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +1 -18
- package/dist/cjs/node/plugin/plugins/devConfig/index.js +2 -4
- package/dist/cjs/node/plugin/plugins/envVars.js +6 -2
- package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +10 -22
- package/dist/cjs/node/plugin/plugins/extractExportNamesPlugin.js +2 -2
- package/dist/cjs/node/plugin/plugins/importBuild/getVikeManifest.js +1 -21
- package/dist/cjs/node/plugin/plugins/importBuild/index.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +29 -95
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +8 -8
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +1 -9
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +3 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +4 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformFileImports.js +35 -36
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +109 -104
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +39 -33
- package/dist/cjs/node/plugin/plugins/setGlobalContext.js +0 -14
- package/dist/cjs/node/plugin/shared/rollupSourceMap.js +20 -0
- package/dist/cjs/node/plugin/utils.js +0 -1
- package/dist/cjs/node/prerender/runPrerender.js +3 -2
- package/dist/cjs/node/prerender/utils.js +1 -1
- package/dist/cjs/node/runtime/globalContext.js +8 -19
- package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +1 -0
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/cjs/node/runtime/renderPage/getPageAssets/assertClientEntryId.js +2 -8
- package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +6 -7
- package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +2 -2
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +23 -28
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -23
- package/dist/cjs/node/runtime/utils.js +1 -2
- package/dist/cjs/node/shared/assertPluginManifest.js +1 -4
- package/dist/cjs/node/shared/assertV1Design.js +26 -0
- package/dist/cjs/node/shared/{getClientEntryFilePath.js → getClientEntry.js} +3 -3
- package/dist/cjs/node/shared/prependEntriesDir.js +13 -0
- package/dist/cjs/node/shared/utils.js +2 -0
- package/dist/cjs/node/shared/virtual-files/virtualFileImportUserCode.js +1 -0
- package/dist/cjs/shared/hooks/getHook.js +1 -1
- package/dist/cjs/shared/page-configs/helpers/getConfigValue.js +1 -0
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +1 -1
- package/dist/cjs/shared/route/abort.js +1 -0
- package/dist/cjs/shared/route/resolvePrecedence.js +1 -0
- package/dist/cjs/utils/{nodeEnv.js → assertNodeEnv.js} +3 -0
- package/dist/cjs/utils/formatHintLog.js +1 -0
- package/dist/cjs/utils/hasProp.js +1 -0
- package/dist/cjs/utils/isScriptFile.js +15 -4
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/__internal/index.js +1 -1
- package/dist/esm/client/shared/loadUserFilesClientSide.js +1 -0
- package/dist/esm/node/plugin/index.js +0 -2
- package/dist/esm/node/plugin/plugins/buildConfig.js +19 -19
- package/dist/esm/node/plugin/plugins/config/index.js +2 -7
- package/dist/esm/node/plugin/plugins/devConfig/determineFsAllowList.d.ts +1 -2
- package/dist/esm/node/plugin/plugins/devConfig/determineFsAllowList.js +1 -8
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.d.ts +1 -2
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +2 -19
- package/dist/esm/node/plugin/plugins/devConfig/index.js +2 -4
- package/dist/esm/node/plugin/plugins/envVars.js +6 -2
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +11 -23
- package/dist/esm/node/plugin/plugins/extractExportNamesPlugin.js +2 -2
- package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.d.ts +1 -2
- package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.js +2 -19
- package/dist/esm/node/plugin/plugins/importBuild/index.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +31 -97
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +8 -8
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +1 -9
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +3 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +4 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformFileImports.d.ts +1 -13
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformFileImports.js +35 -36
- 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 +111 -106
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +39 -33
- package/dist/esm/node/plugin/plugins/setGlobalContext.js +1 -15
- package/dist/esm/node/plugin/shared/rollupSourceMap.d.ts +14 -0
- package/dist/esm/node/plugin/shared/rollupSourceMap.js +17 -0
- package/dist/esm/node/plugin/utils.d.ts +0 -1
- package/dist/esm/node/plugin/utils.js +0 -1
- package/dist/esm/node/prerender/runPrerender.d.ts +3 -3
- package/dist/esm/node/prerender/runPrerender.js +4 -3
- package/dist/esm/node/prerender/utils.d.ts +1 -1
- package/dist/esm/node/prerender/utils.js +1 -1
- package/dist/esm/node/runtime/globalContext.d.ts +3 -10
- package/dist/esm/node/runtime/globalContext.js +7 -18
- package/dist/esm/node/runtime/html/serializePageContextClientSide.js +1 -0
- package/dist/esm/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets/assertClientEntryId.js +2 -8
- package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.js +6 -7
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +2 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +24 -29
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -24
- package/dist/esm/node/runtime/utils.d.ts +1 -2
- package/dist/esm/node/runtime/utils.js +1 -2
- package/dist/esm/node/shared/ViteManifest.d.ts +1 -0
- package/dist/esm/node/shared/assertPluginManifest.d.ts +0 -1
- package/dist/esm/node/shared/assertPluginManifest.js +2 -5
- package/dist/esm/node/shared/assertV1Design.d.ts +4 -0
- package/dist/esm/node/shared/assertV1Design.js +23 -0
- package/dist/esm/node/shared/getClientEntry.d.ts +3 -0
- package/dist/esm/node/shared/{getClientEntryFilePath.js → getClientEntry.js} +2 -2
- package/dist/esm/node/shared/prependEntriesDir.d.ts +2 -0
- package/dist/esm/node/shared/prependEntriesDir.js +10 -0
- package/dist/esm/node/shared/utils.d.ts +2 -0
- package/dist/esm/node/shared/utils.js +2 -0
- package/dist/esm/node/shared/virtual-files/virtualFileImportUserCode.js +1 -0
- package/dist/esm/shared/ConfigVike.d.ts +0 -27
- package/dist/esm/shared/hooks/getHook.js +2 -2
- package/dist/esm/shared/page-configs/Config.d.ts +5 -0
- package/dist/esm/shared/page-configs/PageConfig.d.ts +2 -4
- package/dist/esm/shared/page-configs/helpers/getConfigValue.js +1 -0
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +1 -1
- package/dist/esm/shared/route/abort.js +1 -0
- package/dist/esm/shared/route/resolvePrecedence.js +1 -0
- package/dist/esm/utils/{nodeEnv.js → assertNodeEnv.js} +3 -0
- package/dist/esm/utils/debug.d.ts +1 -1
- package/dist/esm/utils/formatHintLog.js +1 -0
- package/dist/esm/utils/hasProp.js +1 -0
- package/dist/esm/utils/isScriptFile.d.ts +3 -1
- package/dist/esm/utils/isScriptFile.js +14 -3
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +4 -3
- package/dist/cjs/node/plugin/plugins/config/findConfigVikeFromStemPackages.js +0 -27
- package/dist/cjs/node/plugin/plugins/config/resolveExtensions.js +0 -107
- package/dist/cjs/node/plugin/plugins/config/stemUtils.js +0 -85
- package/dist/cjs/node/plugin/plugins/extensionsAssets.js +0 -101
- package/dist/cjs/node/plugin/shared/removeSourceMap.js +0 -12
- package/dist/cjs/utils/getDependencyPackageJson.js +0 -91
- package/dist/cjs/utils/isStemPackageName.js +0 -14
- package/dist/esm/node/plugin/plugins/config/findConfigVikeFromStemPackages.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/config/findConfigVikeFromStemPackages.js +0 -24
- package/dist/esm/node/plugin/plugins/config/resolveExtensions.d.ts +0 -4
- package/dist/esm/node/plugin/plugins/config/resolveExtensions.js +0 -101
- package/dist/esm/node/plugin/plugins/config/stemUtils.d.ts +0 -8
- package/dist/esm/node/plugin/plugins/config/stemUtils.js +0 -79
- package/dist/esm/node/plugin/plugins/extensionsAssets.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/extensionsAssets.js +0 -95
- package/dist/esm/node/plugin/shared/removeSourceMap.d.ts +0 -7
- package/dist/esm/node/plugin/shared/removeSourceMap.js +0 -9
- package/dist/esm/node/shared/getClientEntryFilePath.d.ts +0 -3
- package/dist/esm/utils/getDependencyPackageJson.d.ts +0 -6
- package/dist/esm/utils/getDependencyPackageJson.js +0 -85
- package/dist/esm/utils/isStemPackageName.d.ts +0 -1
- package/dist/esm/utils/isStemPackageName.js +0 -10
- /package/dist/esm/utils/{nodeEnv.d.ts → assertNodeEnv.d.ts} +0 -0
|
@@ -38,7 +38,7 @@ function importUserCode() {
|
|
|
38
38
|
},
|
|
39
39
|
handleHotUpdate(ctx) {
|
|
40
40
|
try {
|
|
41
|
-
return handleHotUpdate(ctx, config
|
|
41
|
+
return handleHotUpdate(ctx, config);
|
|
42
42
|
}
|
|
43
43
|
catch (err) {
|
|
44
44
|
// Vite swallows errors thrown by handleHotUpdate()
|
|
@@ -62,12 +62,12 @@ function importUserCode() {
|
|
|
62
62
|
},
|
|
63
63
|
configureServer(server) {
|
|
64
64
|
(0, utils_js_1.isDev1_onConfigureServer)();
|
|
65
|
-
handleFileAddRemove(server, config
|
|
65
|
+
handleFileAddRemove(server, config);
|
|
66
66
|
}
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
69
|
exports.importUserCode = importUserCode;
|
|
70
|
-
function handleFileAddRemove(server, config
|
|
70
|
+
function handleFileAddRemove(server, config) {
|
|
71
71
|
server.watcher.prependListener('add', (f) => listener(f, false));
|
|
72
72
|
server.watcher.prependListener('unlink', (f) => listener(f, true));
|
|
73
73
|
return;
|
|
@@ -79,11 +79,11 @@ function handleFileAddRemove(server, config, configVike) {
|
|
|
79
79
|
virtualModules.forEach((mod) => {
|
|
80
80
|
server.moduleGraph.invalidateModule(mod);
|
|
81
81
|
});
|
|
82
|
-
reloadConfig(file, config,
|
|
82
|
+
reloadConfig(file, config, isRemove ? 'removed' : 'created');
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
|
-
function handleHotUpdate(ctx, config
|
|
86
|
+
function handleHotUpdate(ctx, config) {
|
|
87
87
|
const { file, server } = ctx;
|
|
88
88
|
(0, utils_js_1.assertPosixPath)(file);
|
|
89
89
|
getVikeConfig_js_1.vikeConfigDependencies.forEach((f) => (0, utils_js_1.assertPosixPath)(f));
|
|
@@ -114,7 +114,7 @@ function handleHotUpdate(ctx, config, configVike) {
|
|
|
114
114
|
/* Tailwind breaks this assertion, see https://github.com/vikejs/vike/discussions/1330#discussioncomment-7787238
|
|
115
115
|
assert(!isViteModule)
|
|
116
116
|
*/
|
|
117
|
-
reloadConfig(file, config,
|
|
117
|
+
reloadConfig(file, config, 'modified');
|
|
118
118
|
const virtualModules = getVirtualModules(server);
|
|
119
119
|
return virtualModules;
|
|
120
120
|
}
|
|
@@ -122,13 +122,13 @@ function handleHotUpdate(ctx, config, configVike) {
|
|
|
122
122
|
function isVikeConfigModule(filePathAbsoluteFilesystem) {
|
|
123
123
|
return getVikeConfig_js_1.vikeConfigDependencies.has(filePathAbsoluteFilesystem);
|
|
124
124
|
}
|
|
125
|
-
function reloadConfig(filePath, config,
|
|
125
|
+
function reloadConfig(filePath, config, op) {
|
|
126
126
|
{
|
|
127
127
|
const filePathToShowToUser = picocolors_1.default.dim((0, utils_js_1.getFilePathRelativeToUserRootDir)(filePath, config.root, true));
|
|
128
128
|
const msg = `${op} ${filePathToShowToUser}`;
|
|
129
129
|
(0, loggerNotProd_js_1.logConfigInfo)(msg, 'info');
|
|
130
130
|
}
|
|
131
|
-
(0, getVikeConfig_js_1.reloadVikeConfig)(config.root, (0, utils_js_1.getOutDirs)(config).outDirRoot
|
|
131
|
+
(0, getVikeConfig_js_1.reloadVikeConfig)(config.root, (0, utils_js_1.getOutDirs)(config).outDirRoot);
|
|
132
132
|
}
|
|
133
133
|
function getVirtualModules(server) {
|
|
134
134
|
const virtualModules = Array.from(server.moduleGraph.urlToModuleMap.keys())
|
|
@@ -66,15 +66,7 @@ function getConfigValueSerialized(value, configName, definedAt) {
|
|
|
66
66
|
*/
|
|
67
67
|
const configValueFilePathToShowToUser = (0, helpers_js_1.getConfigValueFilePathToShowToUser)({ definedAt });
|
|
68
68
|
(0, utils_js_1.assert)(configValueFilePathToShowToUser);
|
|
69
|
-
(0, utils_js_1.assertUsage)(false,
|
|
70
|
-
`The code of ${picocolors_1.default.cyan(configName)} cannot live inside ${configValueFilePathToShowToUser},`,
|
|
71
|
-
'see https://vike.dev/header-file#runtime-code'
|
|
72
|
-
/* I guess showing this is more confusing than adding value.
|
|
73
|
-
`(technically speaking: the value of ${pc.cyan(
|
|
74
|
-
configName
|
|
75
|
-
)} isn't serializable (${serializationErrMsg}) and it's therefore runtime code that needs to be imported).`
|
|
76
|
-
//*/
|
|
77
|
-
].join(' '));
|
|
69
|
+
(0, utils_js_1.assertUsage)(false, `${picocolors_1.default.cyan(configName)} defined by ${configValueFilePathToShowToUser} must be defined over a so-called "pointer import", see https://vike.dev/config#pointer-imports`);
|
|
78
70
|
}
|
|
79
71
|
configValueSerialized = JSON.stringify(configValueSerialized);
|
|
80
72
|
return configValueSerialized;
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js
CHANGED
|
@@ -9,7 +9,7 @@ const utils_js_1 = require("../../../../utils.js");
|
|
|
9
9
|
* The value `locationId` is always a user-land path, because Filesystem Routing/Inheritance only applies to the user-land (Vike never uses Filesystem Routing/Inheritance for `node_modules/**`).
|
|
10
10
|
*/
|
|
11
11
|
function getLocationId(
|
|
12
|
-
// We always determine `locationId` from a real user-land file: the `locationId` for Vike extensions is the `locationId` of the the user's `+config.
|
|
12
|
+
// We always determine `locationId` from a real user-land file: the `locationId` for Vike extensions is the `locationId` of the the user's `+config.js` that extends the Vike extension.
|
|
13
13
|
filePathRelativeToUserRootDir) {
|
|
14
14
|
(0, utils_js_1.assertPosixPath)(filePathRelativeToUserRootDir);
|
|
15
15
|
(0, utils_js_1.assert)(filePathRelativeToUserRootDir.startsWith('/'));
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js
CHANGED
|
@@ -17,7 +17,7 @@ const resolveImportPath_js_1 = require("./resolveImportPath.js");
|
|
|
17
17
|
async function loadImportedFile(import_, userRootDir, importedFilesLoaded) {
|
|
18
18
|
const f = import_.filePathAbsoluteFilesystem;
|
|
19
19
|
if (!importedFilesLoaded[f]) {
|
|
20
|
-
importedFilesLoaded[f] = (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(import_,
|
|
20
|
+
importedFilesLoaded[f] = (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(import_, userRootDir, false).then((r) => r.fileExports);
|
|
21
21
|
}
|
|
22
22
|
const fileExports = await importedFilesLoaded[f];
|
|
23
23
|
const fileExport = fileExports[import_.fileExportName];
|
|
@@ -26,7 +26,7 @@ async function loadImportedFile(import_, userRootDir, importedFilesLoaded) {
|
|
|
26
26
|
exports.loadImportedFile = loadImportedFile;
|
|
27
27
|
// Load +{configName}.js
|
|
28
28
|
async function loadValueFile(interfaceValueFile, configName, userRootDir) {
|
|
29
|
-
const { fileExports } = await (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(interfaceValueFile.filePath,
|
|
29
|
+
const { fileExports } = await (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(interfaceValueFile.filePath, userRootDir, false);
|
|
30
30
|
const { filePathToShowToUser } = interfaceValueFile.filePath;
|
|
31
31
|
(0, assertPlusFileExport_js_1.assertPlusFileExport)(fileExports, filePathToShowToUser, configName);
|
|
32
32
|
Object.entries(fileExports).forEach(([exportName, configValue]) => {
|
|
@@ -36,10 +36,10 @@ async function loadValueFile(interfaceValueFile, configName, userRootDir) {
|
|
|
36
36
|
}
|
|
37
37
|
exports.loadValueFile = loadValueFile;
|
|
38
38
|
// Load +config.js, including all its extends fake imports
|
|
39
|
-
async function loadConfigFile(configFilePath, userRootDir, visited,
|
|
39
|
+
async function loadConfigFile(configFilePath, userRootDir, visited, isExtensionConfig) {
|
|
40
40
|
const { filePathAbsoluteFilesystem } = configFilePath;
|
|
41
41
|
assertNoInfiniteLoop(visited, filePathAbsoluteFilesystem);
|
|
42
|
-
const { fileExports } = await (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(configFilePath,
|
|
42
|
+
const { fileExports } = await (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(configFilePath, userRootDir, isExtensionConfig ? 'is-extension-config' : true);
|
|
43
43
|
const { extendsConfigs, extendsFilePaths } = await loadExtendsConfigs(fileExports, configFilePath, userRootDir, [
|
|
44
44
|
...visited,
|
|
45
45
|
filePathAbsoluteFilesystem
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js
CHANGED
|
@@ -120,7 +120,7 @@ function assertFileEnv(filePathForEnvCheck, configEnv, configName) {
|
|
|
120
120
|
(0, utils_js_1.assertUsage)(false, [
|
|
121
121
|
`${filePathForEnvCheck} defines the value of configs living in different environments:`,
|
|
122
122
|
...[configDifferentEnv, { configName, configEnv }].map((c) => ` - config ${picocolors_1.default.cyan(c.configName)} which value lives in environment ${picocolors_1.default.cyan(JSON.stringify(c.configEnv))}`),
|
|
123
|
-
'Defining config values in the same file is allowed only if they live in the same environment, see https://vike.dev/
|
|
123
|
+
'Defining config values in the same file is allowed only if they live in the same environment, see https://vike.dev/config#pointer-imports'
|
|
124
124
|
].join('\n'));
|
|
125
125
|
}
|
|
126
126
|
}
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformFileImports.js
CHANGED
|
@@ -5,52 +5,55 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.isImportData = exports.parseImportData = exports.transformFileImports = void 0;
|
|
7
7
|
// Playground: https://github.com/brillout/acorn-playground
|
|
8
|
-
//
|
|
9
|
-
//
|
|
8
|
+
// Notes about `with { type: 'pointer' }`
|
|
9
|
+
// - 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
|
|
10
|
+
// - Acorn support for import attributes: https://github.com/acornjs/acorn/issues/983
|
|
11
|
+
// - Acorn plugin: https://github.com/acornjs/acorn/issues/983
|
|
12
|
+
// - Isn't stage 4 yet: https://github.com/tc39/proposal-import-attributes
|
|
13
|
+
// - Using a import path suffix such as `import { Layout } from './Layout?real` breaks TypeScript, and TypeScript isn't working on supporting query params: https://github.com/microsoft/TypeScript/issues/10988#issuecomment-867135453
|
|
14
|
+
// - Node.js >=21 supports import attribtues: https://nodejs.org/api/esm.html#import-attributes
|
|
15
|
+
// - Esbuid supports
|
|
16
|
+
// - Blocker: https://github.com/evanw/esbuild/issues/3646
|
|
17
|
+
// - Ugly hack to make it work: https://github.com/brillout/esbuild-playground/tree/experiment/import-attribute
|
|
18
|
+
// - Discussion with esbuild maintainer: https://github.com/evanw/esbuild/issues/3384
|
|
19
|
+
// - Using a magic comment `// @vike-real-import` is probably a bad idea:
|
|
20
|
+
// - Esbuild removes comments: https://github.com/evanw/esbuild/issues/1439#issuecomment-877656182
|
|
21
|
+
// - Using source maps to track these magic comments is brittle (source maps can easily break)
|
|
10
22
|
const acorn_1 = require("acorn");
|
|
11
23
|
const utils_js_1 = require("../../../../utils.js");
|
|
12
24
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
13
|
-
|
|
25
|
+
// TODO: rename transformFileImports() => transformPointerImports()
|
|
26
|
+
function transformFileImports(code, filePathToShowToUser2, pointerImports,
|
|
14
27
|
// For ./transformFileImports.spec.ts
|
|
15
28
|
skipWarnings) {
|
|
16
29
|
const spliceOperations = [];
|
|
17
|
-
const fileImportsTransformed = [];
|
|
18
30
|
// Performance trick
|
|
19
31
|
if (!code.includes('import'))
|
|
20
|
-
return
|
|
32
|
+
return null;
|
|
21
33
|
const imports = getImports(code);
|
|
22
34
|
if (imports.length === 0)
|
|
23
|
-
return
|
|
35
|
+
return null;
|
|
24
36
|
imports.forEach((node) => {
|
|
25
37
|
if (node.type !== 'ImportDeclaration')
|
|
26
38
|
return;
|
|
27
39
|
const importPath = node.source.value;
|
|
28
40
|
(0, utils_js_1.assert)(typeof importPath === 'string');
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
// - 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
|
|
36
|
-
// - Esbuid seems to support it: https://esbuild.github.io/plugins/#on-load-arguments:~:text=This%20contains%20a%20map%20of%20the%20import%20attributes%20that
|
|
37
|
-
// - acorn supports it over an acorn plugin: https://github.com/acornjs/acorn/issues/983
|
|
38
|
-
// - Maybe we can use an esbuild plugin instead of acorn to apply transformFileImports()?
|
|
39
|
-
// - Using a magic comment `// @vike-real-import` is tricky:
|
|
40
|
-
// - Esbuild removes comments: https://github.com/evanw/esbuild/issues/1439#issuecomment-877656182
|
|
41
|
-
// - Using source maps to track these magic comments is brittle (source maps can easily break)
|
|
42
|
-
if (importPath.endsWith('?real')) {
|
|
43
|
-
const { start, end } = node.source;
|
|
44
|
-
spliceOperations.push({
|
|
45
|
-
start,
|
|
46
|
-
end,
|
|
47
|
-
replacement: importPath.slice(0, -1 * '?real'.length)
|
|
48
|
-
});
|
|
49
|
-
return;
|
|
41
|
+
if (pointerImports !== 'all') {
|
|
42
|
+
(0, utils_js_1.assert)(importPath in pointerImports);
|
|
43
|
+
const isPointerImport = pointerImports[importPath];
|
|
44
|
+
(0, utils_js_1.assert)(isPointerImport === true || isPointerImport === false);
|
|
45
|
+
if (!isPointerImport)
|
|
46
|
+
return;
|
|
50
47
|
}
|
|
51
48
|
const { start, end } = node;
|
|
52
49
|
const importStatementCode = code.slice(start, end);
|
|
53
|
-
|
|
50
|
+
/* Pointer import without importing any value => doesn't make sense and doesn't have any effect.
|
|
51
|
+
```js
|
|
52
|
+
// Useless
|
|
53
|
+
import './some.css'
|
|
54
|
+
// Useless
|
|
55
|
+
import './Layout.jsx'
|
|
56
|
+
``` */
|
|
54
57
|
if (node.specifiers.length === 0) {
|
|
55
58
|
const isWarning = !utils_js_1.styleFileRE.test(importPath);
|
|
56
59
|
let quote = indent(importStatementCode);
|
|
@@ -61,8 +64,9 @@ skipWarnings) {
|
|
|
61
64
|
quote = picocolors_1.default.bold(picocolors_1.default.red(quote));
|
|
62
65
|
}
|
|
63
66
|
const errMsg = [
|
|
64
|
-
`
|
|
65
|
-
quote
|
|
67
|
+
`The following import in ${filePathToShowToUser2} has no effect:`,
|
|
68
|
+
quote,
|
|
69
|
+
'See https://vike.dev/config#pointer-imports'
|
|
66
70
|
].join('\n');
|
|
67
71
|
if (!skipWarnings) {
|
|
68
72
|
if (!isWarning) {
|
|
@@ -91,11 +95,6 @@ skipWarnings) {
|
|
|
91
95
|
})();
|
|
92
96
|
const importString = serializeImportData({ importPath, exportName, importStringWasGenerated: true });
|
|
93
97
|
replacement += `const ${importLocalName} = '${importString}';`;
|
|
94
|
-
fileImportsTransformed.push({
|
|
95
|
-
importStatementCode,
|
|
96
|
-
importString,
|
|
97
|
-
importLocalName
|
|
98
|
-
});
|
|
99
98
|
});
|
|
100
99
|
spliceOperations.push({
|
|
101
100
|
start,
|
|
@@ -104,7 +103,7 @@ skipWarnings) {
|
|
|
104
103
|
});
|
|
105
104
|
});
|
|
106
105
|
const codeMod = spliceMany(code, spliceOperations);
|
|
107
|
-
return
|
|
106
|
+
return codeMod;
|
|
108
107
|
}
|
|
109
108
|
exports.transformFileImports = transformFileImports;
|
|
110
109
|
function getImports(code) {
|
|
@@ -13,62 +13,55 @@ const utils_js_1 = require("../../../../utils.js");
|
|
|
13
13
|
const transformFileImports_js_1 = require("./transformFileImports.js");
|
|
14
14
|
const getVikeConfig_js_1 = require("../getVikeConfig.js");
|
|
15
15
|
require("source-map-support/register.js");
|
|
16
|
-
const getConfigFileExport_js_1 = require("../getConfigFileExport.js");
|
|
17
16
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
const debug = (0, utils_js_1.createDebugger)('vike:pointer-imports');
|
|
18
|
+
async function transpileAndExecuteFile(filePath, userRootDir, isConfigFile) {
|
|
19
|
+
const { filePathAbsoluteFilesystem } = filePath;
|
|
20
|
+
const fileExtension = getFileExtension(filePathAbsoluteFilesystem);
|
|
21
|
+
const filePathToShowToUser2 = getFilePathToShowToUser2(filePath);
|
|
22
|
+
(0, utils_js_1.assertUsage)((0, utils_js_1.isJavaScriptFile)(filePathAbsoluteFilesystem), `${filePathToShowToUser2} has file extension .${fileExtension} but a config file can only be a JavaScript/TypeScript file`);
|
|
23
|
+
const isHeader = isHeaderFile(filePathAbsoluteFilesystem);
|
|
24
|
+
if (isHeader) {
|
|
25
|
+
(0, utils_js_1.assertWarning)(false, `${picocolors_1.default.cyan('.h.js')} files are deprecated: simply renaming ${filePathToShowToUser2} to ${removeHeaderFileExtension(filePathToShowToUser2)} is usually enough, although you may occasionally need to use ${picocolors_1.default.cyan("with { type: 'pointer' }")} as explained at https://vike.dev/config#pointer-imports`, { onlyOnce: true });
|
|
26
|
+
}
|
|
27
|
+
if (isConfigFile === 'is-extension-config' && !isHeader && fileExtension.endsWith('js')) {
|
|
28
|
+
// This doesn't track dependencies => we should never use this for user land configs
|
|
29
|
+
const fileExports = await executeFile(filePathAbsoluteFilesystem, filePath);
|
|
26
30
|
return { fileExports };
|
|
27
31
|
}
|
|
28
32
|
else {
|
|
29
|
-
const
|
|
30
|
-
const
|
|
33
|
+
const transformImports = isConfigFile && (isHeader ? 'all' : true);
|
|
34
|
+
const code = await transpileFile(filePath, transformImports, userRootDir);
|
|
35
|
+
const fileExports = await executeTranspiledFile(filePath, code);
|
|
31
36
|
return { fileExports };
|
|
32
37
|
}
|
|
33
38
|
}
|
|
34
39
|
exports.transpileAndExecuteFile = transpileAndExecuteFile;
|
|
35
40
|
async function transpileFile(filePath, transformImports, userRootDir) {
|
|
36
|
-
const { filePathAbsoluteFilesystem } = filePath;
|
|
37
41
|
const filePathToShowToUser2 = getFilePathToShowToUser2(filePath);
|
|
42
|
+
const { filePathAbsoluteFilesystem } = filePath;
|
|
38
43
|
(0, utils_js_1.assertPosixPath)(filePathAbsoluteFilesystem);
|
|
39
44
|
getVikeConfig_js_1.vikeConfigDependencies.add(filePathAbsoluteFilesystem);
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
if (debug.isEnabled)
|
|
46
|
+
debug('transpile', filePathToShowToUser2);
|
|
47
|
+
let { code, pointerImports } = await transpileWithEsbuild(filePath, userRootDir, transformImports);
|
|
48
|
+
if (debug.isEnabled)
|
|
49
|
+
debug(`code, post esbuild (${filePathToShowToUser2})`, code);
|
|
50
|
+
let isImportTransformed = false;
|
|
42
51
|
if (transformImports) {
|
|
43
|
-
const
|
|
44
|
-
if (
|
|
45
|
-
code =
|
|
46
|
-
|
|
52
|
+
const codeMod = (0, transformFileImports_js_1.transformFileImports)(code, filePathToShowToUser2, pointerImports);
|
|
53
|
+
if (codeMod) {
|
|
54
|
+
code = codeMod;
|
|
55
|
+
isImportTransformed = true;
|
|
56
|
+
if (debug.isEnabled)
|
|
57
|
+
debug(`code, post transformImports() (${filePathToShowToUser2})`, code);
|
|
47
58
|
}
|
|
48
59
|
}
|
|
49
|
-
|
|
50
|
-
if (
|
|
51
|
-
(
|
|
52
|
-
}
|
|
60
|
+
if (!isImportTransformed) {
|
|
61
|
+
if (debug.isEnabled)
|
|
62
|
+
debug(`code, no transformImports() (${filePathToShowToUser2})`);
|
|
53
63
|
}
|
|
54
|
-
return
|
|
55
|
-
}
|
|
56
|
-
function transformFileImports_(codeOriginal, filePath) {
|
|
57
|
-
const { filePathAbsoluteFilesystem } = filePath;
|
|
58
|
-
const filePathToShowToUser2 = getFilePathToShowToUser2(filePath);
|
|
59
|
-
// Replace import statements with import strings
|
|
60
|
-
const res = (0, transformFileImports_js_1.transformFileImports)(codeOriginal, filePathToShowToUser2);
|
|
61
|
-
if (res.noTransformation) {
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
const { code, fileImportsTransformed } = res;
|
|
65
|
-
if (!isHeaderFile(filePathAbsoluteFilesystem)) {
|
|
66
|
-
const filePathCorrect = appendHeaderFileExtension(filePathToShowToUser2);
|
|
67
|
-
(0, utils_js_1.assertWarning)(false, `Rename ${filePathToShowToUser2} to ${filePathCorrect}, see https://vike.dev/header-file`, {
|
|
68
|
-
onlyOnce: true
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
return { code, fileImportsTransformed };
|
|
64
|
+
return code;
|
|
72
65
|
}
|
|
73
66
|
async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
74
67
|
const entryFilePath = filePath.filePathAbsoluteFilesystem;
|
|
@@ -91,14 +84,63 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
91
84
|
// Esbuild still sometimes removes unused imports because of TypeScript: https://github.com/evanw/esbuild/issues/3034
|
|
92
85
|
treeShaking: false,
|
|
93
86
|
minify: false,
|
|
94
|
-
metafile:
|
|
95
|
-
|
|
96
|
-
bundle: !transformImports
|
|
87
|
+
metafile: transformImports !== 'all',
|
|
88
|
+
bundle: transformImports !== 'all'
|
|
97
89
|
};
|
|
98
|
-
|
|
99
|
-
if (
|
|
90
|
+
let pointerImports;
|
|
91
|
+
if (transformImports === 'all') {
|
|
92
|
+
pointerImports = 'all';
|
|
100
93
|
options.packages = 'external';
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
const pointerImports_ = (pointerImports = {});
|
|
101
97
|
options.plugins = [
|
|
98
|
+
// Determine what import should be externalized (and then transformed to a pointer/fake import)
|
|
99
|
+
{
|
|
100
|
+
name: 'vike:externalize-heuristic',
|
|
101
|
+
setup(build) {
|
|
102
|
+
// https://github.com/evanw/esbuild/issues/3095#issuecomment-1546916366
|
|
103
|
+
const useEsbuildResolver = 'useEsbuildResolver';
|
|
104
|
+
// https://github.com/brillout/esbuild-playground
|
|
105
|
+
build.onResolve({ filter: /.*/ }, async (args) => {
|
|
106
|
+
if (args.kind !== 'import-statement')
|
|
107
|
+
return;
|
|
108
|
+
if (args.pluginData?.[useEsbuildResolver])
|
|
109
|
+
return;
|
|
110
|
+
const isImportAbsolute = !args.path.startsWith('.');
|
|
111
|
+
const { path, ...opts } = args;
|
|
112
|
+
opts.pluginData = { [useEsbuildResolver]: true };
|
|
113
|
+
const resolved = await build.resolve(path, opts);
|
|
114
|
+
// vike-{react,vue,solid} follow the convention that their config export resolves to a file named +config.js
|
|
115
|
+
// - This is temporary, see comment below.
|
|
116
|
+
const isVikeExtensionConfigImport = resolved.path.endsWith('+config.js');
|
|
117
|
+
const isPointerImport =
|
|
118
|
+
// .jsx, .vue, .svg, ... => obviously not config code
|
|
119
|
+
!(0, utils_js_1.isJavaScriptFile)(resolved.path) ||
|
|
120
|
+
// 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).
|
|
121
|
+
// - We should have Node.js directly load vike-{react,vue,solid} while enforcing Vike extensions to set 'name' in their +config.js file.
|
|
122
|
+
// - vike@0.4.162 already started soft-requiring Vike extensions to set the name config
|
|
123
|
+
isVikeExtensionConfigImport ||
|
|
124
|
+
// Cannot be resolved by esbuild => take a leap of faith and make it a pointer import.
|
|
125
|
+
// - For example if esbuild cannot resolve a path alias while Vite can.
|
|
126
|
+
// - When tsconfig.js#compilerOptions.paths is set, then esbuild is able to resolve the path alias.
|
|
127
|
+
resolved.errors.length > 0;
|
|
128
|
+
pointerImports_[args.path] = isPointerImport;
|
|
129
|
+
const isExternal = isPointerImport ||
|
|
130
|
+
// npm package imports that aren't pointer imports (e.g. Vite plugin import)
|
|
131
|
+
isImportAbsolute;
|
|
132
|
+
if (debug.isEnabled)
|
|
133
|
+
debug('onResolved()', { args, resolved, isPointerImport, isExternal });
|
|
134
|
+
if (isExternal) {
|
|
135
|
+
return { external: true, path: args.path };
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
return resolved;
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
// Track dependencies
|
|
102
144
|
{
|
|
103
145
|
name: 'vike:dependency-tracker',
|
|
104
146
|
setup(b) {
|
|
@@ -131,7 +173,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
131
173
|
throw err;
|
|
132
174
|
}
|
|
133
175
|
// Track dependencies
|
|
134
|
-
if (
|
|
176
|
+
if (transformImports !== 'all') {
|
|
135
177
|
(0, utils_js_1.assert)(result.metafile);
|
|
136
178
|
Object.keys(result.metafile.inputs).forEach((filePathRelative) => {
|
|
137
179
|
filePathRelative = (0, utils_js_1.toPosixPath)(filePathRelative);
|
|
@@ -142,10 +184,10 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
142
184
|
}
|
|
143
185
|
const code = result.outputFiles[0].text;
|
|
144
186
|
(0, utils_js_1.assert)(typeof code === 'string');
|
|
145
|
-
return code;
|
|
187
|
+
return { code, pointerImports };
|
|
146
188
|
}
|
|
147
|
-
async function executeTranspiledFile(filePath, code
|
|
148
|
-
const { filePathAbsoluteFilesystem
|
|
189
|
+
async function executeTranspiledFile(filePath, code) {
|
|
190
|
+
const { filePathAbsoluteFilesystem } = filePath;
|
|
149
191
|
// Alternative to using a temporary file: https://github.com/vitejs/vite/pull/13269
|
|
150
192
|
// - But seems to break source maps, so I don't think it's worth it
|
|
151
193
|
const filePathTmp = getFilePathTmp(filePathAbsoluteFilesystem);
|
|
@@ -158,11 +200,6 @@ async function executeTranspiledFile(filePath, code, fileImportsTransformed) {
|
|
|
158
200
|
finally {
|
|
159
201
|
clean();
|
|
160
202
|
}
|
|
161
|
-
if (fileImportsTransformed) {
|
|
162
|
-
(0, utils_js_1.assert)(filePathRelativeToUserRootDir !== undefined);
|
|
163
|
-
const filePathToShowToUser2 = getFilePathToShowToUser2(filePath);
|
|
164
|
-
assertImportsAreReExported(fileImportsTransformed, fileExports, filePathToShowToUser2);
|
|
165
|
-
}
|
|
166
203
|
return fileExports;
|
|
167
204
|
}
|
|
168
205
|
async function executeFile(filePathToExecuteAbsoluteFilesystem, filePathSourceFile) {
|
|
@@ -228,59 +265,27 @@ function isTmpFile(filePath) {
|
|
|
228
265
|
return fileName.startsWith(tmpPrefix);
|
|
229
266
|
}
|
|
230
267
|
exports.isTmpFile = isTmpFile;
|
|
231
|
-
function assertImportsAreReExported(fileImportsTransformed, fileExports, filePathToShowToUser2) {
|
|
232
|
-
const fileExport = (0, getConfigFileExport_js_1.getConfigFileExport)(fileExports, filePathToShowToUser2);
|
|
233
|
-
const exportedStrings = getExportedStrings(fileExport);
|
|
234
|
-
Object.values(exportedStrings).forEach((exportVal) => {
|
|
235
|
-
if (typeof exportVal !== 'string')
|
|
236
|
-
return;
|
|
237
|
-
if (!(0, transformFileImports_js_1.isImportData)(exportVal))
|
|
238
|
-
return;
|
|
239
|
-
const importString = exportVal;
|
|
240
|
-
fileImportsTransformed.forEach((fileImport) => {
|
|
241
|
-
if (fileImport.importString === importString) {
|
|
242
|
-
fileImport.isReExported = true;
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
});
|
|
246
|
-
const fileImportsTransformedUnused = fileImportsTransformed.filter((fi) => !fi.isReExported);
|
|
247
|
-
if (fileImportsTransformedUnused.length === 0)
|
|
248
|
-
return;
|
|
249
|
-
const importStatements = (0, utils_js_1.unique)(fileImportsTransformedUnused.map((fi) => fi.importStatementCode));
|
|
250
|
-
const importNamesUnused = fileImportsTransformedUnused.map((fi) => picocolors_1.default.cyan(fi.importLocalName)).join(', ');
|
|
251
|
-
const singular = fileImportsTransformedUnused.length === 1;
|
|
252
|
-
(0, utils_js_1.assertWarning)(fileImportsTransformedUnused.length === 0, [
|
|
253
|
-
`${filePathToShowToUser2} imports the following:`,
|
|
254
|
-
...importStatements.map((s) => picocolors_1.default.cyan(` ${s}`)),
|
|
255
|
-
`But the import${singular ? '' : 's'} ${importNamesUnused} ${singular ? "isn't" : "aren't"} re-exported at ${picocolors_1.default.cyan('export default { ... }')} and therefore ${singular ? 'has' : 'have'} no effect, see explanation at https://vike.dev/header-file`
|
|
256
|
-
].join('\n'), { onlyOnce: true });
|
|
257
|
-
}
|
|
258
|
-
function getExportedStrings(obj) {
|
|
259
|
-
const exportedStrings = [];
|
|
260
|
-
Object.values(obj).forEach((val) => {
|
|
261
|
-
if (typeof val === 'string') {
|
|
262
|
-
exportedStrings.push(val);
|
|
263
|
-
}
|
|
264
|
-
else if (Array.isArray(val)) {
|
|
265
|
-
val.forEach((v) => {
|
|
266
|
-
if (typeof v === 'string') {
|
|
267
|
-
exportedStrings.push(v);
|
|
268
|
-
}
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
return exportedStrings;
|
|
273
|
-
}
|
|
274
268
|
function isHeaderFile(filePath) {
|
|
275
269
|
(0, utils_js_1.assertPosixPath)(filePath);
|
|
276
|
-
const
|
|
277
|
-
return
|
|
270
|
+
const fileExtensions = getFileExtensions(filePath);
|
|
271
|
+
return fileExtensions.includes('h');
|
|
278
272
|
}
|
|
279
|
-
function
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
273
|
+
function getFileExtensions(filePath) {
|
|
274
|
+
const fileExtensions = path_1.default.posix.basename(filePath).split('.').slice(1);
|
|
275
|
+
return fileExtensions;
|
|
276
|
+
}
|
|
277
|
+
function getFileExtension(filePath) {
|
|
278
|
+
const fileExtensions = path_1.default.posix.basename(filePath).split('.').slice(1);
|
|
279
|
+
return fileExtensions.pop();
|
|
280
|
+
}
|
|
281
|
+
function removeHeaderFileExtension(filePath) {
|
|
282
|
+
(0, utils_js_1.assertPosixPath)(filePath);
|
|
283
|
+
const fileName = path_1.default.posix.basename(filePath);
|
|
284
|
+
const fileNameParts = fileName.split('.');
|
|
285
|
+
const fileNamePartsMod = fileNameParts.filter((p) => p !== 'h');
|
|
286
|
+
(0, utils_js_1.assert)(fileNamePartsMod.length < fileNameParts.length);
|
|
287
|
+
const fileNameMod = fileNamePartsMod.join('.');
|
|
288
|
+
return path_1.default.posix.join(path_1.default.posix.dirname(filePath), fileNameMod);
|
|
284
289
|
}
|
|
285
290
|
// Needed for the npm package 'source-map-support'. The Error.prepareStackTrace() hook of 'source-map-support' needs to be called before the file containing the source map is removed. The clean() call above removes the transpiled file from disk but it contains the inline source map.
|
|
286
291
|
function triggerPrepareStackTrace(err) {
|