@common-stack/rollup-vite-utils 5.0.4-alpha.8 → 5.0.5-alpha.9
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/lib/constants/constants.cjs +4 -0
- package/lib/constants/constants.cjs.map +1 -0
- package/lib/constants/constants.d.ts +1 -0
- package/lib/constants/constants.js +2 -1
- package/lib/constants/constants.js.map +1 -1
- package/lib/default-config.json.cjs +31 -0
- package/lib/default-config.json.cjs.map +1 -0
- package/lib/index.cjs +1 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.js +1 -1
- package/lib/preStartup/configLoader/configLoader.cjs +27 -0
- package/lib/preStartup/configLoader/configLoader.cjs.map +1 -0
- package/lib/preStartup/configLoader/envLoader.cjs +10 -0
- package/lib/preStartup/configLoader/envLoader.cjs.map +1 -0
- package/lib/preStartup/configLoader/index.cjs +1 -0
- package/lib/preStartup/configLoader/index.cjs.map +1 -0
- package/lib/preStartup/copyIfVersionChanged.cjs +110 -0
- package/lib/preStartup/copyIfVersionChanged.cjs.map +1 -0
- package/lib/rollup/modifyLibFiles/extractGraphQLQueries.cjs +59 -0
- package/lib/rollup/modifyLibFiles/extractGraphQLQueries.cjs.map +1 -0
- package/lib/rollup/modifyLibFiles/handleComponentOrDialog.cjs +236 -0
- package/lib/rollup/modifyLibFiles/handleComponentOrDialog.cjs.map +1 -0
- package/lib/rollup/modifyLibFiles/handleIconSVGFiles.cjs +25 -0
- package/lib/rollup/modifyLibFiles/handleIconSVGFiles.cjs.map +1 -0
- package/lib/rollup/modifyLibFiles/handleWrappers.cjs +34 -0
- package/lib/rollup/modifyLibFiles/handleWrappers.cjs.map +1 -0
- package/lib/rollup/modifyLibFiles/utils.cjs +19 -0
- package/lib/rollup/modifyLibFiles/utils.cjs.map +1 -0
- package/lib/rollup/pluginIgnore.cjs +17 -0
- package/lib/rollup/pluginIgnore.cjs.map +1 -0
- package/lib/rollup/rollupPluginAddJsExtension.cjs +68 -0
- package/lib/rollup/rollupPluginAddJsExtension.cjs.map +1 -0
- package/lib/rollup/rollupPluginGenerateJson.cjs +39 -0
- package/lib/rollup/rollupPluginGenerateJson.cjs.map +1 -0
- package/lib/rollup/rollupPluginModifyLibFiles.cjs +50 -0
- package/lib/rollup/rollupPluginModifyLibFiles.cjs.map +1 -0
- package/lib/utils/setupConfig.cjs +65 -0
- package/lib/utils/setupConfig.cjs.map +1 -0
- package/lib/utils/utils.cjs +188 -0
- package/lib/utils/utils.cjs.map +1 -0
- package/lib/utils/utils.d.ts +12 -0
- package/lib/utils/utils.js +98 -2
- package/lib/utils/utils.js.map +1 -1
- package/lib/utils/withErrorHandleUtil.cjs +92 -0
- package/lib/utils/withErrorHandleUtil.cjs.map +1 -0
- package/lib/vite-plugins/i18n-internationalization-plugin.cjs +93 -0
- package/lib/vite-plugins/i18n-internationalization-plugin.cjs.map +1 -0
- package/lib/vite-plugins/vite-plugin-virutal-imports.cjs +27 -0
- package/lib/vite-plugins/vite-plugin-virutal-imports.cjs.map +1 -0
- package/lib/vite-wrappers/dialog-wrapper.cjs +53 -0
- package/lib/vite-wrappers/dialog-wrapper.cjs.map +1 -0
- package/lib/vite-wrappers/icon-switch.cjs +89 -0
- package/lib/vite-wrappers/icon-switch.cjs.map +1 -0
- package/lib/vite-wrappers/json-wrappers.cjs +132 -0
- package/lib/vite-wrappers/json-wrappers.cjs.map +1 -0
- package/lib/vite-wrappers/loaderGenerator.cjs +245 -0
- package/lib/vite-wrappers/loaderGenerator.cjs.map +1 -0
- package/lib/vite-wrappers/wrapperComponent.cjs +336 -0
- package/lib/vite-wrappers/wrapperComponent.cjs.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
'use strict';const MODULES_JS = 'modules.js';
|
|
2
|
+
const MODULES_TS = 'module.ts';
|
|
3
|
+
const SYNC_META_JSON = 'sync-meta.json';
|
|
4
|
+
const QUERY_PARAMS_GENERATOR = 'queryParamsGenerator';exports.MODULES_JS=MODULES_JS;exports.MODULES_TS=MODULES_TS;exports.QUERY_PARAMS_GENERATOR=QUERY_PARAMS_GENERATOR;exports.SYNC_META_JSON=SYNC_META_JSON;//# sourceMappingURL=constants.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.cjs","sources":["../../src/constants/constants.ts"],"sourcesContent":[null],"names":[],"mappings":"aAIO,MAAM,UAAU,GAAG,aAAa;AAChC,MAAM,UAAU,GAAG,YAAY;AAC/B,MAAM,cAAc,GAAG,iBAAiB;AACxC,MAAM,sBAAsB,GAAG"}
|
|
@@ -2,5 +2,6 @@ export declare const MODULES_JSON = "modules.json";
|
|
|
2
2
|
export declare const ROUTES_JSON = "routes.json";
|
|
3
3
|
export declare const COMPUTE_JS = "compute.js";
|
|
4
4
|
export declare const MODULES_JS = "modules.js";
|
|
5
|
+
export declare const MODULES_TS = "module.ts";
|
|
5
6
|
export declare const SYNC_META_JSON = "sync-meta.json";
|
|
6
7
|
export declare const QUERY_PARAMS_GENERATOR = "queryParamsGenerator";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
const MODULES_JS = 'modules.js';
|
|
2
|
+
const MODULES_TS = 'module.ts';
|
|
2
3
|
const SYNC_META_JSON = 'sync-meta.json';
|
|
3
|
-
const QUERY_PARAMS_GENERATOR = 'queryParamsGenerator';export{MODULES_JS,QUERY_PARAMS_GENERATOR,SYNC_META_JSON};//# sourceMappingURL=constants.js.map
|
|
4
|
+
const QUERY_PARAMS_GENERATOR = 'queryParamsGenerator';export{MODULES_JS,MODULES_TS,QUERY_PARAMS_GENERATOR,SYNC_META_JSON};//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sources":["../../src/constants/constants.ts"],"sourcesContent":[null],"names":[],"mappings":"AAIO,MAAM,UAAU,GAAG,aAAa;AAChC,MAAM,cAAc,GAAG,iBAAiB;AACxC,MAAM,sBAAsB,GAAG"}
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../src/constants/constants.ts"],"sourcesContent":[null],"names":[],"mappings":"AAIO,MAAM,UAAU,GAAG,aAAa;AAChC,MAAM,UAAU,GAAG,YAAY;AAC/B,MAAM,cAAc,GAAG,iBAAiB;AACxC,MAAM,sBAAsB,GAAG"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';Object.defineProperty(exports,'__esModule',{value:true});var commonPaths = {
|
|
2
|
+
appPath: "app",
|
|
3
|
+
frontendStackPath: "frontend-stack-react"
|
|
4
|
+
};
|
|
5
|
+
var copyOperations = [
|
|
6
|
+
{
|
|
7
|
+
packageName: "@common-stack/frontend-stack-react",
|
|
8
|
+
destPath: "$.commonPaths.frontendStackPath",
|
|
9
|
+
generateModule: true
|
|
10
|
+
}
|
|
11
|
+
];
|
|
12
|
+
var modules = [
|
|
13
|
+
"@adminide-stack/platform-browser"
|
|
14
|
+
];
|
|
15
|
+
var uiFramework = "antui";
|
|
16
|
+
var paths = {
|
|
17
|
+
permissionWrapper: "@adminide-stack/platform-browser/lib/components/Permission/WithPermission.js",
|
|
18
|
+
configurationWrapper: "@adminide-stack/platform-browser/lib/components/Configuration/WithConfiguration.js",
|
|
19
|
+
authMiddlware: "@adminide-stack/user-auth0-client/lib/auth/authValidatorMiddleware.js",
|
|
20
|
+
lifecycleMiddleware: "@adminide-stack/platform-client/lib/middleware/lifecycleMiddleware.js",
|
|
21
|
+
middlewareExec: "@common-stack/frontend-stack-react/lib/tools/loaderWithMiddleware.js",
|
|
22
|
+
clientMiddlewareExec: "@common-stack/frontend-stack-react/lib/tools/clientLoaderWithMiddleware.js",
|
|
23
|
+
withErrorHandlerUtil: "@common-stack/rollup-vite-utils/lib/utils/withErrorHandleUtil.js"
|
|
24
|
+
};
|
|
25
|
+
var defaultConfig = {
|
|
26
|
+
commonPaths: commonPaths,
|
|
27
|
+
copyOperations: copyOperations,
|
|
28
|
+
modules: modules,
|
|
29
|
+
uiFramework: uiFramework,
|
|
30
|
+
paths: paths
|
|
31
|
+
};exports.commonPaths=commonPaths;exports.copyOperations=copyOperations;exports.default=defaultConfig;exports.modules=modules;exports.paths=paths;exports.uiFramework=uiFramework;//# sourceMappingURL=default-config.json.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-config.json.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/lib/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var wrapperComponent=require('./vite-wrappers/wrapperComponent.cjs'),jsonWrappers=require('./vite-wrappers/json-wrappers.cjs'),rollupPluginGenerateJson=require('./rollup/rollupPluginGenerateJson.cjs'),rollupPluginModifyLibFiles=require('./rollup/rollupPluginModifyLibFiles.cjs'),rollupPluginAddJsExtension=require('./rollup/rollupPluginAddJsExtension.cjs'),pluginIgnore=require('./rollup/pluginIgnore.cjs'),copyIfVersionChanged=require('./preStartup/copyIfVersionChanged.cjs');require('./preStartup/configLoader/index.cjs');var i18nInternationalizationPlugin=require('./vite-plugins/i18n-internationalization-plugin.cjs'),vitePluginVirutalImports=require('./vite-plugins/vite-plugin-virutal-imports.cjs'),utils=require('./utils/utils.cjs'),withErrorHandleUtil=require('./utils/withErrorHandleUtil.cjs'),setupConfig=require('./utils/setupConfig.cjs'),configLoader=require('./preStartup/configLoader/configLoader.cjs'),envLoader=require('./preStartup/configLoader/envLoader.cjs');exports.getRootPath=wrapperComponent.getRootPath;exports.wrapRouteComponent=wrapperComponent.wrapRouteComponent;exports.defineRoutesConfig=jsonWrappers.defineRoutesConfig;exports.loadRoutesConfig=jsonWrappers.loadRoutesConfig;exports.resolvePathsUsingPackages=jsonWrappers.resolvePathsUsingPackages;exports.d=rollupPluginGenerateJson;exports.k=rollupPluginModifyLibFiles;exports.l=rollupPluginAddJsExtension;exports.m=pluginIgnore;exports.copyIfVersionChanged=copyIfVersionChanged.copyIfVersionChanged;exports.i18nInternationalizationPlugin=i18nInternationalizationPlugin.i18nInternationalizationPlugin;exports.virtualImportsPlugin=vitePluginVirutalImports.virtualImportsPlugin;exports.findPackageDir=utils.findPackageDir;exports.generateBackendModulesFile=utils.generateBackendModulesFile;exports.generateModulesFile=utils.generateModulesFile;exports.getMetadata=utils.getMetadata;exports.getPackageVersion=utils.getPackageVersion;exports.updateMetadata=utils.updateMetadata;exports.writeBackendModuleFile=utils.writeBackendModuleFile;exports.writeModuleFile=utils.writeModuleFile;exports.withErrorHandler=withErrorHandleUtil.withErrorHandler;exports.setupConfig=setupConfig.setupConfig;exports.performCopyOperations=configLoader.performCopyOperations;exports.resolveConfigPaths=configLoader.resolveConfigPaths;exports.loadEnvConfig=envLoader.loadEnvConfig;//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{getRootPath,wrapRouteComponent}from'./vite-wrappers/wrapperComponent.js';export{defineRoutesConfig,loadRoutesConfig,resolvePathsUsingPackages}from'./vite-wrappers/json-wrappers.js';import*as rollupPluginGenerateJson from'./rollup/rollupPluginGenerateJson.js';export{rollupPluginGenerateJson as d };import*as rollupPluginModifyLibFiles from'./rollup/rollupPluginModifyLibFiles.js';export{rollupPluginModifyLibFiles as k };import*as rollupPluginAddJsExtension from'./rollup/rollupPluginAddJsExtension.js';export{rollupPluginAddJsExtension as l };import*as pluginIgnore from'./rollup/pluginIgnore.js';export{pluginIgnore as m };export{copyIfVersionChanged}from'./preStartup/copyIfVersionChanged.js';import'./preStartup/configLoader/index.js';export{i18nInternationalizationPlugin}from'./vite-plugins/i18n-internationalization-plugin.js';export{virtualImportsPlugin}from'./vite-plugins/vite-plugin-virutal-imports.js';export{findPackageDir,generateModulesFile,getMetadata,getPackageVersion,updateMetadata,writeModuleFile}from'./utils/utils.js';export{withErrorHandler}from'./utils/withErrorHandleUtil.js';export{setupConfig}from'./utils/setupConfig.js';export{performCopyOperations,resolveConfigPaths}from'./preStartup/configLoader/configLoader.js';export{loadEnvConfig}from'./preStartup/configLoader/envLoader.js';//# sourceMappingURL=index.js.map
|
|
1
|
+
export{getRootPath,wrapRouteComponent}from'./vite-wrappers/wrapperComponent.js';export{defineRoutesConfig,loadRoutesConfig,resolvePathsUsingPackages}from'./vite-wrappers/json-wrappers.js';import*as rollupPluginGenerateJson from'./rollup/rollupPluginGenerateJson.js';export{rollupPluginGenerateJson as d };import*as rollupPluginModifyLibFiles from'./rollup/rollupPluginModifyLibFiles.js';export{rollupPluginModifyLibFiles as k };import*as rollupPluginAddJsExtension from'./rollup/rollupPluginAddJsExtension.js';export{rollupPluginAddJsExtension as l };import*as pluginIgnore from'./rollup/pluginIgnore.js';export{pluginIgnore as m };export{copyIfVersionChanged}from'./preStartup/copyIfVersionChanged.js';import'./preStartup/configLoader/index.js';export{i18nInternationalizationPlugin}from'./vite-plugins/i18n-internationalization-plugin.js';export{virtualImportsPlugin}from'./vite-plugins/vite-plugin-virutal-imports.js';export{findPackageDir,generateBackendModulesFile,generateModulesFile,getMetadata,getPackageVersion,updateMetadata,writeBackendModuleFile,writeModuleFile}from'./utils/utils.js';export{withErrorHandler}from'./utils/withErrorHandleUtil.js';export{setupConfig}from'./utils/setupConfig.js';export{performCopyOperations,resolveConfigPaths}from'./preStartup/configLoader/configLoader.js';export{loadEnvConfig}from'./preStartup/configLoader/envLoader.js';//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';var copyIfVersionChanged=require('../copyIfVersionChanged.cjs');function resolvePath(config, path) {
|
|
2
|
+
if (typeof path === 'string' && path.startsWith('$.')) {
|
|
3
|
+
return path.split('.').slice(1).reduce((o, p) => (o ? o[p] : undefined), config);
|
|
4
|
+
}
|
|
5
|
+
return path;
|
|
6
|
+
}
|
|
7
|
+
function resolveConfigPaths(config) {
|
|
8
|
+
return {
|
|
9
|
+
...config,
|
|
10
|
+
copyOperations: config.copyOperations.map(op => ({
|
|
11
|
+
...op,
|
|
12
|
+
destPath: resolvePath(config, op.destPath)
|
|
13
|
+
}))
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
async function performCopyOperations(config) {
|
|
17
|
+
const resolvedConfig = resolveConfigPaths(config);
|
|
18
|
+
for (const operation of resolvedConfig.copyOperations) {
|
|
19
|
+
try {
|
|
20
|
+
await copyIfVersionChanged.copyIfVersionChanged(operation.packageName, resolvedConfig.commonPaths.appPath, operation.destPath, operation.generateModule, operation.symbolicLink, resolvedConfig.modules, resolvedConfig.copyOperations);
|
|
21
|
+
console.log(`Copy operation for ${operation.packageName} completed successfully.`);
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
console.error(`Error in copy process for ${operation.packageName}:`, err);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}exports.performCopyOperations=performCopyOperations;exports.resolveConfigPaths=resolveConfigPaths;//# sourceMappingURL=configLoader.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configLoader.cjs","sources":["../../../src/preStartup/configLoader/configLoader.ts"],"sourcesContent":[null],"names":["copyIfVersionChanged"],"mappings":"6EAEA,SAAS,WAAW,CAAC,MAAM,EAAE,IAAI,EAAA;AAC7B,IAAA,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;AACnD,QAAA,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,EAAE,MAAM,CAAC,CAAC;KACpF;AACD,IAAA,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,SAAS,kBAAkB,CAAC,MAAM,EAAA;IAC9B,OAAO;AACH,QAAA,GAAG,MAAM;QACT,cAAc,EAAE,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,KAAK;AAC7C,YAAA,GAAG,EAAE;YACL,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,EAAE,CAAC,QAAQ,CAAC;AAC7C,SAAA,CAAC,CAAC;KACN,CAAC;AACN,CAAC;AAID,eAAe,qBAAqB,CAAC,MAAM,EAAA;AACvC,IAAA,MAAM,cAAc,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;AAClD,IAAA,KAAK,MAAM,SAAS,IAAI,cAAc,CAAC,cAAc,EAAE;AACnD,QAAA,IAAI;AACA,YAAA,MAAMA,yCAAoB,CACtB,SAAS,CAAC,WAAW,EACrB,cAAc,CAAC,WAAW,CAAC,OAAO,EAClC,SAAS,CAAC,QAAQ,EAClB,SAAS,CAAC,cAAc,EACxB,SAAS,CAAC,YAAY,EACtB,cAAc,CAAC,OAAO,EACtB,cAAc,CAAC,cAAc,CAChC,CAAC;YACF,OAAO,CAAC,GAAG,CAAC,CAAA,mBAAA,EAAsB,SAAS,CAAC,WAAW,CAA0B,wBAAA,CAAA,CAAC,CAAC;SACtF;QAAC,OAAO,GAAG,EAAE;YACV,OAAO,CAAC,KAAK,CAAC,CAA6B,0BAAA,EAAA,SAAS,CAAC,WAAW,CAAG,CAAA,CAAA,EAAE,GAAG,CAAC,CAAC;SAC7E;KACJ;AACL"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';var path=require('path'),dotenv=require('dotenv-esm');function loadEnvConfig(directoryName) {
|
|
2
|
+
let dotEnvResult;
|
|
3
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
4
|
+
dotEnvResult = dotenv.config({ path: path.resolve(directoryName, process.env.ENV_FILE) });
|
|
5
|
+
if (dotEnvResult.error) {
|
|
6
|
+
throw dotEnvResult.error;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return dotEnvResult;
|
|
10
|
+
}exports.loadEnvConfig=loadEnvConfig;//# sourceMappingURL=envLoader.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envLoader.cjs","sources":["../../../src/preStartup/configLoader/envLoader.ts"],"sourcesContent":[null],"names":["resolve"],"mappings":"mEAGM,SAAU,aAAa,CAAC,aAAa,EAAA;AACvC,IAAA,IAAI,YAAY,CAAC;IACjB,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;QACvC,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAEA,YAAO,CAAC,aAAa,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AACrF,QAAA,IAAI,YAAY,CAAC,KAAK,EAAE;YACpB,MAAM,YAAY,CAAC,KAAK,CAAC;SAC5B;KACJ;AACD,IAAA,OAAO,YAAY,CAAC;AACxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var node=require('@remix-run/node');require('fs-extra'),require('path'),require('semver'),require('dotenv-esm');node.installGlobals();//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../src/preStartup/configLoader/index.ts"],"sourcesContent":[null],"names":["installGlobals"],"mappings":"6HAKAA,mBAAc,EAAE"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
'use strict';var fs=require('fs-extra'),path=require('path'),semver=require('semver'),utils=require('../utils/utils.cjs'),constants=require('../constants/constants.cjs');/**
|
|
2
|
+
* Copy the contents from srcDir to destDir if the version in srcDir is different from destDir.
|
|
3
|
+
* Also update modules.js based on modules.json if required.
|
|
4
|
+
* @param packageName - The name of the package.
|
|
5
|
+
* @param appDirRelative - The relative path to the application directory.
|
|
6
|
+
* @param destDirRelative - The relative path to the destination directory.
|
|
7
|
+
* @param updateModules - Boolean flag indicating if modules.js should be updated.
|
|
8
|
+
* @param useSymlink - Boolean flag indicating if symbolic link should be used instead of copy.
|
|
9
|
+
*/
|
|
10
|
+
async function copyIfVersionChanged(packageName, appDirRelative, destDirRelative, updateModules = false, useSymlink = false, modulePackages = [], resolvedConfigCopyOps = []) {
|
|
11
|
+
const initialDir = process.cwd();
|
|
12
|
+
const srcPackageDir = utils.findPackageDir(initialDir, packageName);
|
|
13
|
+
if (!srcPackageDir) {
|
|
14
|
+
console.error(`Failed to find package directory for ${packageName}`);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const appDir = path.resolve(initialDir, appDirRelative);
|
|
18
|
+
const destDir = path.resolve(appDir, destDirRelative);
|
|
19
|
+
const srcDir = path.join(srcPackageDir, 'lib');
|
|
20
|
+
const srcVersion = await utils.getPackageVersion(srcPackageDir);
|
|
21
|
+
const metadata = await utils.getMetadata(appDir);
|
|
22
|
+
const moduleMetadata = metadata[packageName];
|
|
23
|
+
const srcStat = await fs.stat(srcDir).catch(() => null);
|
|
24
|
+
// Collect all package names from copyOperations
|
|
25
|
+
const copyOperationPackageNames = resolvedConfigCopyOps.map((op) => op.packageName);
|
|
26
|
+
// Check if any packageName in metadata is not in copyOperations
|
|
27
|
+
const metadataKeys = Object.keys(metadata);
|
|
28
|
+
const missingKeys = metadataKeys.filter(key => !copyOperationPackageNames.includes(key));
|
|
29
|
+
const isMetadataDifferentFromConfig = missingKeys.length > 0;
|
|
30
|
+
if (isMetadataDifferentFromConfig) {
|
|
31
|
+
// Handle missing keys and their copied paths
|
|
32
|
+
for (const key of missingKeys) {
|
|
33
|
+
const copiedPath = metadata[key]?.copiedPath;
|
|
34
|
+
if (copiedPath) {
|
|
35
|
+
try {
|
|
36
|
+
delete metadata[key];
|
|
37
|
+
await fs.remove(copiedPath);
|
|
38
|
+
console.log(`Removed ${copiedPath}`);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
console.error(`Error removing ${copiedPath}:`, error);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (!srcVersion) {
|
|
47
|
+
console.error('Source package.json not found or has no version.');
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
// Check if the destination path is a directory or a file
|
|
51
|
+
const destStat = await fs.lstat(destDir).catch(() => null);
|
|
52
|
+
if (destStat && !destStat.isDirectory()) {
|
|
53
|
+
// If it's not a directory, remove it to avoid overwrite errors
|
|
54
|
+
await fs.remove(destDir);
|
|
55
|
+
}
|
|
56
|
+
if (useSymlink || !moduleMetadata || isMetadataDifferentFromConfig ||
|
|
57
|
+
semver.gt(srcVersion, moduleMetadata.version) ||
|
|
58
|
+
!srcStat ||
|
|
59
|
+
(srcStat && srcStat.mtime > new Date(moduleMetadata.timestamp))) {
|
|
60
|
+
try {
|
|
61
|
+
if (useSymlink) {
|
|
62
|
+
// Remove existing symlink or directory if it exists
|
|
63
|
+
if (await fs.pathExists(destDir)) {
|
|
64
|
+
const isSymlink = await fs.lstat(destDir).then(stat => stat.isSymbolicLink()).catch(() => false);
|
|
65
|
+
if (!isSymlink) {
|
|
66
|
+
await fs.remove(destDir);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
await fs.ensureSymlink(srcDir, destDir);
|
|
70
|
+
console.log(`Created symlink for ${packageName} from ${srcDir} to ${destDir}`);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
// Remove existing directory if it exists to avoid conflicts
|
|
74
|
+
if (await fs.pathExists(destDir)) {
|
|
75
|
+
await fs.remove(destDir);
|
|
76
|
+
}
|
|
77
|
+
await fs.copy(srcDir, destDir, {
|
|
78
|
+
overwrite: true,
|
|
79
|
+
filter: (src) => {
|
|
80
|
+
return !src.endsWith('package.json');
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
console.log(`Copied ${packageName} to ${destDir} as versions differ or destination didn't exist.`);
|
|
84
|
+
}
|
|
85
|
+
metadata[packageName] = {
|
|
86
|
+
srcPackageDir,
|
|
87
|
+
version: srcVersion,
|
|
88
|
+
copiedPath: destDir,
|
|
89
|
+
timestamp: new Date().toISOString(),
|
|
90
|
+
};
|
|
91
|
+
await utils.updateMetadata(appDir, metadata);
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
console.error(`Error ${useSymlink ? 'creating symlink' : 'copying directory'}:`, err);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
console.log(`Destination for ${packageName} is up-to-date. No ${useSymlink ? 'symlink' : 'copying'} needed.`);
|
|
99
|
+
}
|
|
100
|
+
// Optionally update modules.js based on modules.json
|
|
101
|
+
if (updateModules) {
|
|
102
|
+
try {
|
|
103
|
+
utils.writeModuleFile(destDir, modulePackages);
|
|
104
|
+
console.log(`Updated ${path.join(destDir, constants.MODULES_JS)} based on config.json.`);
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
console.error('Error updating modules.js:', err);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}exports.copyIfVersionChanged=copyIfVersionChanged;//# sourceMappingURL=copyIfVersionChanged.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copyIfVersionChanged.cjs","sources":["../../src/preStartup/copyIfVersionChanged.ts"],"sourcesContent":[null],"names":["findPackageDir","getPackageVersion","getMetadata","updateMetadata","writeModuleFile","MODULES_JS"],"mappings":"0KAMA;;;;;;;;AAQG;AACI,eAAe,oBAAoB,CACtC,WAAmB,EACnB,cAAsB,EACtB,eAAuB,EACvB,aAAyB,GAAA,KAAK,EAC9B,UAAsB,GAAA,KAAK,EAC3B,cAA2B,GAAA,EAAE,EAC7B,qBAAA,GAA4B,EAAE,EAAA;AAE9B,IAAA,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IACjC,MAAM,aAAa,GAAGA,oBAAc,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;IAE9D,IAAI,CAAC,aAAa,EAAE;AAChB,QAAA,OAAO,CAAC,KAAK,CAAC,wCAAwC,W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S,GAAG,SAAS,CAAA,QAAA,CAAU,CAAC,CAAC;KACjH;;IAGD,IAAI,aAAa,EAAE;AACf,QAAA,IAAI;AACA,YAAAC,qBAAe,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;AACzC,YAAA,OAAO,CAAC,GAAG,CAAC,CAAA,QAAA,EAAW,IAAI,CAAC,IAAI,CAAC,OAAO,EAAEC,oBAAU,CAAC,CAAA,sBAAA,CAAwB,CAAC,CAAC;SAClF;QAAC,OAAO,GAAG,EAAE;AACV,YAAA,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAAC;SACpD;KACJ;AACL"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use strict';var traverseSource=require('@babel/traverse'),parser=require('@babel/parser'),fs=require('fs'),constants=require('../../constants/constants.cjs');// to support esm default
|
|
2
|
+
// https://github.com/babel/babel/issues/15269#issuecomment-1505804243
|
|
3
|
+
const traverse = traverseSource.default ?? traverseSource;
|
|
4
|
+
const extractGraphQLQueries = (filePath) => {
|
|
5
|
+
const code = fs.readFileSync(filePath, { encoding: 'utf-8' });
|
|
6
|
+
const ast = parser.parse(code, {
|
|
7
|
+
sourceType: 'module',
|
|
8
|
+
plugins: ['jsx', 'typescript'],
|
|
9
|
+
});
|
|
10
|
+
const queries = {};
|
|
11
|
+
const queryRegExp = /^use(.+?)(?<!Lazy)Query$/;
|
|
12
|
+
traverse(ast, {
|
|
13
|
+
ImportSpecifier(innerPath) {
|
|
14
|
+
if (innerPath.node.imported.type !== 'Identifier')
|
|
15
|
+
return;
|
|
16
|
+
const hookName = innerPath.node.imported?.name;
|
|
17
|
+
const [_, queryNameMatch] = hookName.match(queryRegExp) ?? [];
|
|
18
|
+
if (queryNameMatch && !hookName.startsWith('useLazy') && !hookName.startsWith('useMutation')) {
|
|
19
|
+
queries[`${queryNameMatch}Document`] = null; // Placeholder for variables
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
CallExpression(innerPath) {
|
|
23
|
+
const { callee } = innerPath.node;
|
|
24
|
+
if (callee.type === 'Identifier') {
|
|
25
|
+
const hookName = callee.name;
|
|
26
|
+
const [_, queryNameMatch] = hookName.match(queryRegExp) ?? [];
|
|
27
|
+
const documentName = `${queryNameMatch}Document`;
|
|
28
|
+
if (!(documentName in queries)) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const [options] = innerPath.node.arguments;
|
|
32
|
+
if (options?.type !== 'ObjectExpression') {
|
|
33
|
+
queries[documentName] = '{}'; // No variables passed
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const variables = options.properties.find((i) => i.type === 'ObjectProperty' && i.key.type === 'Identifier' && i?.key.name === 'variables');
|
|
37
|
+
if (variables?.type === 'ObjectProperty') {
|
|
38
|
+
const { properties, object } = variables.value;
|
|
39
|
+
const isQueryParamGenerator = object?.callee?.name === constants.QUERY_PARAMS_GENERATOR;
|
|
40
|
+
if (!properties && isQueryParamGenerator) {
|
|
41
|
+
let vars = `${constants.QUERY_PARAMS_GENERATOR}_${variables.value.property.name}`;
|
|
42
|
+
queries[documentName] = vars;
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
let vars = `{${properties?.length === 0 ? '}' : ''}`;
|
|
46
|
+
properties?.forEach(({ key, value }, index) => {
|
|
47
|
+
if (!key || !value)
|
|
48
|
+
return;
|
|
49
|
+
const hasValue = value.value !== null && value.value !== undefined;
|
|
50
|
+
const valueExpr = hasValue ? value.value : `params.${key.name}`;
|
|
51
|
+
vars += `${key.name}: ${valueExpr}${properties?.length === index + 1 ? '}' : ','}`;
|
|
52
|
+
}, '{');
|
|
53
|
+
queries[documentName] = vars;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
return queries;
|
|
59
|
+
};exports.extractGraphQLQueries=extractGraphQLQueries;//# sourceMappingURL=extractGraphQLQueries.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":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C,GAAG,IAAI,CAAA;wBAC5B,OAAM;qBACT;AAED,oBAAA,IAAI,IAAI,GAAG,CAAA,CAAA,EAAI,UAAU,EAAE,MAAM,KAAK,CAAC,GAAG,GAAG,GAAG,EAAE,EAAE,CAAC;AACrD,oBAAA,UAAU,EAAE,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,KAAK,KAAI;AAC1C,wBAAA,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK;4BAAE,OAAO;AAC3B,wBAAA,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC;AACnE,wBAAA,MAAM,SAAS,GAAG,QAAQ,GAAG,KAAK,CAAC,KAAK,GAAG,CAAA,OAAA,EAAU,GAAG,CAAC,IAAI,EAAE,CAAC;wBAChE,IAAI,IAAI,CAAG,EAAA,GAAG,CAAC,IAAI,KAAK,SAAS,CAAA,EAAG,UAAU,EAAE,MAAM,KAAK,KAAK,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,CAAA,CAAE,CAAC;qBACtF,EAAE,GAAG,CAAC,CAAC;AACR,oBAAA,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC;iBAChC;aACJ;SACJ;AACJ,KAAA,CAAC,CAAC;AACH,IAAA,OAAO,OAAO,CAAC;AACnB"}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
'use strict';var fs=require('fs'),path=require('path'),parser=require('@babel/parser'),traverseSource=require('@babel/traverse'),generateSource=require('@babel/generator'),t=require('@babel/types'),util=require('util'),glob=require('glob'),extractGraphQLQueries=require('./extractGraphQLQueries.cjs'),utils=require('./utils.cjs');function _interopNamespaceDefault(e){var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var t__namespace=/*#__PURE__*/_interopNamespaceDefault(t);/* eslint-disable import/no-extraneous-dependencies */
|
|
2
|
+
// to support esm default
|
|
3
|
+
// https://github.com/babel/babel/issues/15269#issuecomment-1505804243
|
|
4
|
+
const traverse = traverseSource.default ?? traverseSource;
|
|
5
|
+
const generate = generateSource.default ?? generateSource;
|
|
6
|
+
util.promisify(glob);
|
|
7
|
+
const RouteModule = {
|
|
8
|
+
action: 'action',
|
|
9
|
+
hasAction: 'hasAction',
|
|
10
|
+
clientAction: 'clientAction',
|
|
11
|
+
hasClientAction: 'hasClientAction',
|
|
12
|
+
clientLoader: 'clientLoader',
|
|
13
|
+
hasClientLoader: 'hasClientLoader',
|
|
14
|
+
Component: 'default', // default export
|
|
15
|
+
hasComponent: 'hasComponent',
|
|
16
|
+
ErrorBoundary: 'ErrorBoundary',
|
|
17
|
+
hasErrorBoundary: 'hasErrorBoundary',
|
|
18
|
+
handle: 'handle',
|
|
19
|
+
hasHandle: 'hasHandle',
|
|
20
|
+
queryParamsGenerator: "queryParamsGenerator",
|
|
21
|
+
headers: 'headers',
|
|
22
|
+
hasHeaders: 'hasHeaders',
|
|
23
|
+
HydrateFallback: 'HydrateFallback',
|
|
24
|
+
hasHydrateFallback: 'hasHydrateFallback',
|
|
25
|
+
links: 'links',
|
|
26
|
+
hasLinks: 'hasLinks',
|
|
27
|
+
loader: 'loader',
|
|
28
|
+
hasLoader: 'hasLoader',
|
|
29
|
+
meta: 'meta',
|
|
30
|
+
hasMeta: 'hasMeta',
|
|
31
|
+
shouldRevalidate: 'shouldRevalidate',
|
|
32
|
+
hasShouldRevalidate: 'hasShouldRevalidate',
|
|
33
|
+
};
|
|
34
|
+
function parseFileToAST(filePath, plugins) {
|
|
35
|
+
const fileContent = fs.readFileSync(filePath, 'utf8');
|
|
36
|
+
return parser.parse(fileContent, {
|
|
37
|
+
sourceType: 'module',
|
|
38
|
+
plugins,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function writeModifiedASTToFile(filePath, ast, originalCode) {
|
|
42
|
+
const output = generate(ast, {}, originalCode);
|
|
43
|
+
fs.writeFileSync(filePath, output.code);
|
|
44
|
+
}
|
|
45
|
+
function getFunctionName(path) {
|
|
46
|
+
if (path.isFunctionDeclaration() || path.isFunctionExpression()) {
|
|
47
|
+
return path.node.id ? path.node.id.name : null;
|
|
48
|
+
}
|
|
49
|
+
if (path.parent && path.parent.type === 'VariableDeclarator' && t__namespace.isIdentifier(path.parent.id)) {
|
|
50
|
+
return path.parent.id.name;
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
function simplifyReturnStatement(returnPath, returnInfo) {
|
|
55
|
+
const { argument } = returnPath.node;
|
|
56
|
+
if (argument && ((argument.type === 'CallExpression' && argument.callee.type === 'Identifier' && (argument.callee.name === 'defer' || argument.callee.name === 'json')) ||
|
|
57
|
+
argument.type === 'ObjectExpression')) {
|
|
58
|
+
const args = argument.type === 'CallExpression' ? argument.arguments : [argument];
|
|
59
|
+
if (args.length > 0 && args[0].type === 'ObjectExpression' && args[0].properties.length > 0) {
|
|
60
|
+
const { properties } = args[0];
|
|
61
|
+
const valuesArray = properties
|
|
62
|
+
.map((prop) => {
|
|
63
|
+
const { value } = prop;
|
|
64
|
+
if (t__namespace.isExpression(value)) {
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
})
|
|
69
|
+
.filter(Boolean);
|
|
70
|
+
properties.forEach((prop) => {
|
|
71
|
+
const { key } = prop;
|
|
72
|
+
if (t__namespace.isIdentifier(key)) {
|
|
73
|
+
returnInfo.keys.push(key.name);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
const objectProperties = [
|
|
77
|
+
t__namespace.objectProperty(t__namespace.identifier('data'), t__namespace.arrayExpression(valuesArray)),
|
|
78
|
+
];
|
|
79
|
+
if (args.length > 1 && args[1].type === 'ObjectExpression') {
|
|
80
|
+
returnInfo.hasOptions = true;
|
|
81
|
+
objectProperties.push(t__namespace.objectProperty(t__namespace.identifier('options'), args[1]));
|
|
82
|
+
}
|
|
83
|
+
returnPath.node.argument = t__namespace.objectExpression(objectProperties);
|
|
84
|
+
returnInfo.returnType = argument.type === 'CallExpression' && t__namespace.isIdentifier(argument.callee)
|
|
85
|
+
? argument.callee.name
|
|
86
|
+
: 'json';
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
function modifyReturn(filePath, loaderName) {
|
|
93
|
+
const ast = parseFileToAST(filePath, ['typescript', 'jsx']);
|
|
94
|
+
const returnInfo = { returnType: '', keys: [], hasOptions: false };
|
|
95
|
+
let modified = false;
|
|
96
|
+
traverse(ast, {
|
|
97
|
+
'FunctionDeclaration|ArrowFunctionExpression|FunctionExpression': function (path) {
|
|
98
|
+
const functionName = getFunctionName(path);
|
|
99
|
+
if (functionName === loaderName ||
|
|
100
|
+
path.parent.type === 'ExportDefaultDeclaration' ||
|
|
101
|
+
(path.parent.type === 'ExportNamedDeclaration' && path.parent.declaration === path.node)) {
|
|
102
|
+
path.traverse({
|
|
103
|
+
ReturnStatement(returnPath) {
|
|
104
|
+
modified = simplifyReturnStatement(returnPath, returnInfo) || modified;
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
if (modified) {
|
|
111
|
+
writeModifiedASTToFile(filePath, ast, fs.readFileSync(filePath, 'utf8'));
|
|
112
|
+
}
|
|
113
|
+
return returnInfo;
|
|
114
|
+
}
|
|
115
|
+
function extractLoaderInfo(importedAst, fullPath) {
|
|
116
|
+
const loaderInfo = {
|
|
117
|
+
hasLoader: false,
|
|
118
|
+
hasAction: false,
|
|
119
|
+
hasClientLoader: false,
|
|
120
|
+
hasClientAction: false,
|
|
121
|
+
hasComponent: false,
|
|
122
|
+
hasErrorBoundary: false,
|
|
123
|
+
hasLinks: false,
|
|
124
|
+
hasMeta: false,
|
|
125
|
+
queryParamsGenerator: false,
|
|
126
|
+
hasHydrateFallback: false,
|
|
127
|
+
hasShouldRevalidate: false,
|
|
128
|
+
hasHandle: false,
|
|
129
|
+
hasHeaders: false,
|
|
130
|
+
};
|
|
131
|
+
let returnInfo = { returnType: '', keys: [], hasOptions: false };
|
|
132
|
+
let queries = {};
|
|
133
|
+
traverse(importedAst, {
|
|
134
|
+
ExportNamedDeclaration(namedPath) {
|
|
135
|
+
if (namedPath.node.source) {
|
|
136
|
+
const loaderSourcePath = namedPath.node.source.value;
|
|
137
|
+
fullPath = path.resolve(path.dirname(fullPath), loaderSourcePath);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
fullPath = fullPath;
|
|
141
|
+
}
|
|
142
|
+
namedPath.node.specifiers.forEach((specifier) => {
|
|
143
|
+
if (t__namespace.isExportSpecifier(specifier) && t__namespace.isIdentifier(specifier.exported)) {
|
|
144
|
+
switch (specifier.exported.name) {
|
|
145
|
+
case RouteModule.loader:
|
|
146
|
+
loaderInfo.hasLoader = true;
|
|
147
|
+
returnInfo = modifyReturn(fullPath, specifier.local.name);
|
|
148
|
+
break;
|
|
149
|
+
case RouteModule.action:
|
|
150
|
+
loaderInfo.hasAction = true;
|
|
151
|
+
break;
|
|
152
|
+
case RouteModule.queryParamsGenerator:
|
|
153
|
+
loaderInfo.queryParamsGenerator = true;
|
|
154
|
+
break;
|
|
155
|
+
case RouteModule.Component:
|
|
156
|
+
loaderInfo.hasComponent = true;
|
|
157
|
+
queries = extractGraphQLQueries.extractGraphQLQueries(fullPath);
|
|
158
|
+
break;
|
|
159
|
+
case RouteModule.ErrorBoundary:
|
|
160
|
+
loaderInfo.hasErrorBoundary = true;
|
|
161
|
+
break;
|
|
162
|
+
case RouteModule.clientLoader:
|
|
163
|
+
loaderInfo.hasClientLoader = true;
|
|
164
|
+
break;
|
|
165
|
+
case RouteModule.clientAction:
|
|
166
|
+
loaderInfo.hasClientAction = true;
|
|
167
|
+
break;
|
|
168
|
+
case RouteModule.headers:
|
|
169
|
+
loaderInfo.hasHeaders = true;
|
|
170
|
+
break;
|
|
171
|
+
case RouteModule.links:
|
|
172
|
+
loaderInfo.hasLinks = true;
|
|
173
|
+
break;
|
|
174
|
+
case RouteModule.meta:
|
|
175
|
+
loaderInfo.hasMeta = true;
|
|
176
|
+
break;
|
|
177
|
+
case RouteModule.shouldRevalidate:
|
|
178
|
+
loaderInfo.hasShouldRevalidate = true;
|
|
179
|
+
break;
|
|
180
|
+
case RouteModule.HydrateFallback:
|
|
181
|
+
loaderInfo.hasHydrateFallback = true;
|
|
182
|
+
break;
|
|
183
|
+
case RouteModule.handle:
|
|
184
|
+
loaderInfo.hasHandle = true;
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
return { loaderInfo, returnInfo, queries };
|
|
192
|
+
}
|
|
193
|
+
function handleComponentOrDialog(astroPath, filePath, dist) {
|
|
194
|
+
const importDeclaration = astroPath.node.value;
|
|
195
|
+
const propName = astroPath.node.key.name;
|
|
196
|
+
if (t__namespace.isArrowFunctionExpression(importDeclaration) && t__namespace.isCallExpression(importDeclaration.body) && t__namespace.isImport(importDeclaration.body.callee)) {
|
|
197
|
+
const importArg = importDeclaration.body.arguments[0];
|
|
198
|
+
if (t__namespace.isStringLiteral(importArg)) {
|
|
199
|
+
const importPath = importArg.value;
|
|
200
|
+
const normalizedImportPath = utils.processImportPaths(importPath, filePath, dist);
|
|
201
|
+
const fileProperty = t__namespace.objectProperty(t__namespace.identifier(`${propName}Path`), t__namespace.stringLiteral(normalizedImportPath));
|
|
202
|
+
const parentObject = astroPath.findParent((p) => p.isObjectExpression());
|
|
203
|
+
if (parentObject && t__namespace.isObjectExpression(parentObject.node)) {
|
|
204
|
+
astroPath.remove();
|
|
205
|
+
parentObject.node.properties.push(fileProperty);
|
|
206
|
+
const fullPath = path.resolve(path.dirname(filePath), importPath);
|
|
207
|
+
if (fs.existsSync(fullPath)) {
|
|
208
|
+
const importedFileCode = fs.readFileSync(fullPath, 'utf8');
|
|
209
|
+
const importedAst = parser.parse(importedFileCode, {
|
|
210
|
+
sourceType: 'module',
|
|
211
|
+
plugins: ['typescript', 'jsx'],
|
|
212
|
+
});
|
|
213
|
+
const { loaderInfo, returnInfo, queries } = extractLoaderInfo(importedAst, fullPath);
|
|
214
|
+
for (const key in loaderInfo) {
|
|
215
|
+
if (loaderInfo[key]) {
|
|
216
|
+
parentObject.node.properties.push(t__namespace.objectProperty(t__namespace.identifier(RouteModule[key]), t__namespace.booleanLiteral(true)));
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (returnInfo.keys.length > 0) {
|
|
220
|
+
const returnInfoObject = t__namespace.objectExpression([
|
|
221
|
+
t__namespace.objectProperty(t__namespace.identifier('returnType'), t__namespace.stringLiteral(returnInfo.returnType)),
|
|
222
|
+
t__namespace.objectProperty(t__namespace.identifier('hasOptions'), t__namespace.booleanLiteral(returnInfo.hasOptions)),
|
|
223
|
+
t__namespace.objectProperty(t__namespace.identifier('keys'), t__namespace.arrayExpression(returnInfo.keys.map((key) => t__namespace.stringLiteral(key)))),
|
|
224
|
+
]);
|
|
225
|
+
parentObject.node.properties.push(t__namespace.objectProperty(t__namespace.identifier('loaderReturnInfo'), returnInfoObject));
|
|
226
|
+
}
|
|
227
|
+
if (queries) {
|
|
228
|
+
parentObject.node.properties.push(t__namespace.objectProperty(t__namespace.identifier('queries'), t__namespace.objectExpression(Object.entries(queries).map(([key, value]) => t__namespace.objectProperty(t__namespace.identifier(key), t__namespace.stringLiteral(value ?? '{}'))))));
|
|
229
|
+
}
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return false;
|
|
236
|
+
}exports.handleComponentOrDialog=handleComponentOrDialog;//# sourceMappingURL=handleComponentOrDialog.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleComponentOrDialog.cjs","sources":["../../../src/rollup/modifyLibFiles/handleComponentOrDialog.ts"],"sourcesContent":[null],"names":["promisify","parse","t","extractGraphQLQueries","processImportPaths"],"mappings":"kqBAAA;AAcA;AACA;AACA,MAAM,QAAQ,GAAI,cAAsB,CAAC,OAAO,IAAI,cAAc,CAAC;AACnE,MAAM,QAAQ,GAAI,cAAsB,CAAC,OAAO,IAAI,cAAc,CAAC;AAC/CA,cAAS,CAAC,IAAI,EAAE;AAEpC,MAAM,WAAW,GAAG;AAChB,IAAA,MAAM,EAAE,QAAQ;AAChB,IAAA,SAAS,EAAE,WAAW;AACtB,IAAA,YAAY,EAAE,cAAc;AAC5B,IAAA,eAAe,EAAE,iBAAiB;AAClC,IAAA,YAAY,EAAE,cAAc;AAC5B,IAAA,eAAe,EAAE,iBAAiB;IAClC,SAAS,EAAE,SAAS;AACpB,IAAA,YAAY,EAAE,cAAc;AAC5B,IAAA,aAAa,EAAE,eAAe;AAC9B,IAAA,gBAAgB,EAAE,kBAAkB;AACpC,IAAA,MAAM,EAAE,QAAQ;AAChB,IAAA,SAAS,EAAE,WAAW;AACtB,IAAA,oBAAoB,EAAE,sBAAsB;AAC5C,IAAA,OAAO,EAAE,SAAS;AAClB,IAAA,UAAU,EAAE,YAAY;AACxB,IAAA,eAAe,EAAE,iBAAiB;AAClC,IAAA,kBAAkB,EAAE,oBAAoB;AACxC,IAAA,KAAK,EAAE,OAAO;AACd,IAAA,QAAQ,EAAE,UAAU;AACpB,IAAA,MAAM,EAAE,QAAQ;AAChB,IAAA,SAAS,EAAE,WAAW;AACtB,IAAA,IAAI,EAAE,MAAM;AACZ,IAAA,OAAO,EAAE,SAAS;AAClB,IAAA,gBAAgB,EAAE,kBAAkB;AACpC,IAAA,mBAAmB,EAAE,qBAAqB;CAC7C,CAAC;AA0BF,SAAS,cAAc,CAAC,QAAgB,EAAE,OAAiC,EAAA;IACvE,MAAM,WAAW,GAAG,EAAE,CAAC,YAAY,CA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,YAAC,CAAC,UAAU,CAAC,SAAS,CAAC,EACvBA,YAAC,CAAC,gBAAgB,CACd,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KACrCA,YAAC,CAAC,cAAc,CAACA,YAAC,CAAC,UAAU,CAAC,GAAG,CAAC,EAAEA,YAAC,CAAC,aAAa,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,CACtE,CACJ,CACJ,CACJ,CAAC;qBACL;AACD,oBAAA,OAAO,IAAI,CAAC;iBACf;aACJ;SACJ;KACJ;AACD,IAAA,OAAO,KAAK,CAAC;AACjB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';var t=require('@babel/types'),utils=require('./utils.cjs');function _interopNamespaceDefault(e){var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var t__namespace=/*#__PURE__*/_interopNamespaceDefault(t);function handleIconSVGFiles(astroPath, filePath, dist) {
|
|
2
|
+
const iconNode = astroPath.node.value;
|
|
3
|
+
const svgIndex = iconNode.properties.findIndex((prop) => t__namespace.isObjectProperty(prop) && t__namespace.isIdentifier(prop.key) && prop.key.name === 'svg');
|
|
4
|
+
const svgJsIndex = iconNode.properties.findIndex((prop) => t__namespace.isObjectProperty(prop) && t__namespace.isIdentifier(prop.key) && prop.key.name === 'svgJsPath');
|
|
5
|
+
const index = svgIndex !== -1 ? svgIndex : svgJsIndex;
|
|
6
|
+
if (index !== -1) {
|
|
7
|
+
const svgNode = iconNode.properties[index];
|
|
8
|
+
const svgKeyName = index === svgIndex ? `svgPath` : `svgJsPath`;
|
|
9
|
+
if (t__namespace.isObjectProperty(svgNode) &&
|
|
10
|
+
t__namespace.isArrowFunctionExpression(svgNode.value) &&
|
|
11
|
+
t__namespace.isCallExpression(svgNode.value.body) &&
|
|
12
|
+
t__namespace.isImport(svgNode.value.body.callee)) {
|
|
13
|
+
const importArg = svgNode.value.body.arguments[0];
|
|
14
|
+
if (t__namespace.isStringLiteral(importArg)) {
|
|
15
|
+
const importPath = importArg.value;
|
|
16
|
+
const normalizedImportPath = utils.processImportPaths(importPath, filePath, dist);
|
|
17
|
+
const fileProperty = t__namespace.objectProperty(t__namespace.identifier(svgKeyName), t__namespace.stringLiteral(normalizedImportPath));
|
|
18
|
+
iconNode.properties.splice(index, 1);
|
|
19
|
+
iconNode.properties.push(fileProperty);
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
}exports.handleIconSVGFiles=handleIconSVGFiles;//# sourceMappingURL=handleIconSVGFiles.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleIconSVGFiles.cjs","sources":["../../../src/rollup/modifyLibFiles/handleIconSVGFiles.ts"],"sourcesContent":[null],"names":["t","processImportPaths"],"mappings":"yaAIgB,kBAAkB,CAAC,SAAqC,EAAE,QAAgB,EAAE,IAAY,EAAA;AACpG,IAAA,MAAM,QAAQ,GAAG,SAAS,CAAC,IAAI,CAAC,KAA2B,CAAC;AAC5D,IAAA,MAAM,QAAQ,GAAG,QAAQ,CAAC,UAAU,CAAC,SAAS,CAC1C,CAAC,IAAI,KAAKA,YAAC,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAIA,YAAC,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,KAAK,CAC5F,CAAC;AACF,IAAA,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC,SAAS,CAC5C,CAAC,IAAI,KAAKA,YAAC,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAIA,YAAC,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,IAAI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