tungsten 0.1.59 → 0.1.61
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/AnyComponent.d.ts.map +1 -1
- package/dist/ComponentInstance.d.ts +1 -2
- package/dist/ComponentInstance.d.ts.map +1 -1
- package/dist/ComponentInstance.js +4 -1
- package/dist/ComponentRenderInfo.type.d.ts +6 -0
- package/dist/ComponentRenderInfo.type.d.ts.map +1 -0
- package/dist/ComponentRenderInfo.type.js +1 -0
- package/dist/Components.d.ts +18 -2
- package/dist/Components.d.ts.map +1 -1
- package/dist/Components.js +105 -4
- package/dist/ContentNode.d.ts +3 -1
- package/dist/ContentNode.d.ts.map +1 -1
- package/dist/ContentNode.js +1 -0
- package/dist/Framework.d.ts +1 -1
- package/dist/Framework.d.ts.map +1 -1
- package/dist/Framework.js +42 -25
- package/dist/FrameworkConfig.d.ts +20 -4
- package/dist/FrameworkConfig.d.ts.map +1 -1
- package/dist/FunctionComponent.d.ts +2 -0
- package/dist/FunctionComponent.d.ts.map +1 -1
- package/dist/FunctionComponentStandIn.d.ts +9 -4
- package/dist/FunctionComponentStandIn.d.ts.map +1 -1
- package/dist/FunctionComponentStandIn.js +17 -2
- package/dist/Instance/Instance.d.ts.map +1 -1
- package/dist/Instance/InstanceConfig.d.ts +2 -0
- package/dist/Instance/InstanceConfig.d.ts.map +1 -1
- package/dist/RenderedContentNode.d.ts +6 -1
- package/dist/RenderedContentNode.d.ts.map +1 -1
- package/dist/RenderedContentNode.js +2 -2
- package/dist/RenderingNode.d.ts +23 -8
- package/dist/RenderingNode.d.ts.map +1 -1
- package/dist/RenderingNode.js +39 -8
- package/dist/Servers/DevServer.d.ts.map +1 -1
- package/dist/Servers/DevServer.js +74 -25
- package/dist/Servers/ProdServer.d.ts +5 -1
- package/dist/Servers/ProdServer.d.ts.map +1 -1
- package/dist/Servers/ProdServer.js +49 -33
- package/dist/Store/makeStore.d.ts.map +1 -1
- package/dist/TungstenApp.d.ts +11 -0
- package/dist/TungstenApp.d.ts.map +1 -0
- package/dist/TungstenApp.js +46 -0
- package/dist/TungstenElement.d.ts +3 -0
- package/dist/TungstenElement.d.ts.map +1 -0
- package/dist/TungstenElement.js +1 -0
- package/dist/_client/client.d.ts +4 -1
- package/dist/_client/client.d.ts.map +1 -1
- package/dist/_client/client.js +16 -9
- package/dist/babelPlugins/BabelTransformBindDirect.d.ts.map +1 -1
- package/dist/babelPlugins/BabelTransformBindVar.d.ts.map +1 -1
- package/dist/babelPlugins/BabelTransformCjsToEsm.d.ts +1 -1
- package/dist/babelPlugins/BabelTransformCjsToEsm.d.ts.map +1 -1
- package/dist/babelPlugins/BabelTransformCjsToFunction.d.ts +1 -1
- package/dist/babelPlugins/BabelTransformCjsToFunction.d.ts.map +1 -1
- package/dist/babelPlugins/BabelTransformCjsToFunction2.d.ts +1 -1
- package/dist/babelPlugins/BabelTransformCjsToFunction2.d.ts.map +1 -1
- package/dist/babelPlugins/BabelTransformComponentState.d.ts.map +1 -1
- package/dist/babelPlugins/BabelTransformComponentStyles.d.ts.map +1 -1
- package/dist/babelPlugins/{BabelTransformCssImport.d.ts → BabelTransformCssImports.d.ts} +5 -3
- package/dist/babelPlugins/BabelTransformCssImports.d.ts.map +1 -0
- package/dist/babelPlugins/BabelTransformCssImports.js +129 -0
- package/dist/babelPlugins/BabelTransformDependencyImportsOld.d.ts.map +1 -1
- package/dist/babelPlugins/BabelTransformDeproxyState.d.ts.map +1 -1
- package/dist/babelPlugins/BabelTransformPackageImports.d.ts.map +1 -1
- package/dist/babelPlugins/BabelTransformPackageImports.js +110 -45
- package/dist/babelPlugins/BabelTransformReactive.d.ts.map +1 -1
- package/dist/babelPlugins/BabelTransformReactiveSvelteStyle.d.ts.map +1 -1
- package/dist/babelPlugins/BabelTransformRemoveServerBlocks.d.ts.map +1 -1
- package/dist/babelPlugins/BabelTransformRemoveServerBlocks.js +5 -0
- package/dist/babelPlugins/BabelTransformRemoveServerCode.d.ts +2 -0
- package/dist/babelPlugins/BabelTransformRemoveServerCode.d.ts.map +1 -0
- package/dist/babelPlugins/BabelTransformRemoveServerCode.js +1 -0
- package/dist/babelPlugins/BabelTransformUniqueComponents.d.ts.map +1 -1
- package/dist/babelPlugins/fixImportsInSassErrorMessage.d.ts.map +1 -1
- package/dist/babelPlugins/{BabelTransformDependencyImportsCjs.d.ts → transformPackageImports/BabelTransformDependencyImportsCjs.d.ts} +1 -1
- package/dist/babelPlugins/transformPackageImports/BabelTransformDependencyImportsCjs.d.ts.map +1 -0
- package/dist/babelPlugins/{BabelTransformDependencyImportsCjs.js → transformPackageImports/BabelTransformDependencyImportsCjs.js} +10 -3
- package/dist/babelPlugins/{BabelTransformDependencyImportsEsm.d.ts → transformPackageImports/BabelTransformDependencyImportsEsm.d.ts} +1 -1
- package/dist/babelPlugins/transformPackageImports/BabelTransformDependencyImportsEsm.d.ts.map +1 -0
- package/dist/babelPlugins/transformPackageImports/BabelTransformDependencyImportsEsm.js +112 -0
- package/dist/babelPlugins/transformPackageImports/getWebLocationOfPackageFile.d.ts +2 -0
- package/dist/babelPlugins/transformPackageImports/getWebLocationOfPackageFile.d.ts.map +1 -0
- package/dist/babelPlugins/transformPackageImports/getWebLocationOfPackageFile.js +24 -0
- package/dist/bin/commands/compileSimplePackage.d.ts +2 -0
- package/dist/bin/commands/compileSimplePackage.d.ts.map +1 -0
- package/dist/bin/commands/compileSimplePackage.js +51 -0
- package/dist/bin/commands/static.js +2 -2
- package/dist/bin/index.d.ts.map +1 -1
- package/dist/bin/index.js +5 -0
- package/dist/browserStorage.d.ts.map +1 -1
- package/dist/build/babel.user.common.config.d.ts.map +1 -1
- package/dist/build/babel.user.common.config.js +2 -56
- package/dist/build/bundle.d.ts +1 -2
- package/dist/build/bundle.d.ts.map +1 -1
- package/dist/build/bundle.js +7 -4
- package/dist/build/compileJavascript.d.ts.map +1 -1
- package/dist/build/compileJavascript.js +23 -11
- package/dist/build/compilePackages.d.ts +0 -5
- package/dist/build/compilePackages.d.ts.map +1 -1
- package/dist/build/compilePackages.js +89 -82
- package/dist/build/compileUserApp.d.ts.map +1 -1
- package/dist/build/copyPackageModulesToPackagesFolder.d.ts.map +1 -1
- package/dist/build/copyPackageModulesToPackagesFolder.js +3 -1
- package/dist/build/createClientFiles.d.ts.map +1 -1
- package/dist/build/createClientFiles.js +43 -52
- package/dist/build/createInstanceConfigFile.d.ts +4 -0
- package/dist/build/createInstanceConfigFile.d.ts.map +1 -0
- package/dist/build/{createAppConfig.js → createInstanceConfigFile.js} +2 -2
- package/dist/build/makeBabelUserDevConfig.d.ts.map +1 -1
- package/dist/build/makeBabelUserDevConfig.js +8 -14
- package/dist/build/makeBabelUserProdConfig.d.ts.map +1 -1
- package/dist/build/makeBabelUserProdConfig.js +4 -5
- package/dist/componentProxyHandlers.d.ts.map +1 -1
- package/dist/components/Link.d.ts.map +1 -1
- package/dist/components/Link.js +1 -1
- package/dist/components/Stylesheet.d.ts.map +1 -1
- package/dist/components/Stylesheet.js +5 -3
- package/dist/createRef.d.ts +4 -2
- package/dist/createRef.d.ts.map +1 -1
- package/dist/createRef.js +5 -2
- package/dist/createRoutes.d.ts +3 -0
- package/dist/createRoutes.d.ts.map +1 -0
- package/dist/createRoutes.js +3 -0
- package/dist/defaultConfig.d.ts +1 -0
- package/dist/defaultConfig.d.ts.map +1 -1
- package/dist/defaultConfig.js +1 -0
- package/dist/findUserConfig.d.ts.map +1 -1
- package/dist/findUserConfig.js +1 -1
- package/dist/frameworkConfigSchema.d.ts +188 -0
- package/dist/frameworkConfigSchema.d.ts.map +1 -0
- package/dist/frameworkConfigSchema.js +65 -0
- package/dist/getConfig.d.ts +1 -15
- package/dist/getConfig.d.ts.map +1 -1
- package/dist/getConfig.js +12 -11
- package/dist/getRoutes.d.ts.map +1 -1
- package/dist/getRoutes.js +20 -15
- package/dist/getUserConfig.d.ts +3 -0
- package/dist/getUserConfig.d.ts.map +1 -0
- package/dist/getUserConfig.js +25 -0
- package/dist/hasDomain.d.ts.map +1 -1
- package/dist/hooks/getCurrentComponent.d.ts +4 -0
- package/dist/hooks/getCurrentComponent.d.ts.map +1 -1
- package/dist/hooks/getCurrentComponent.js +8 -2
- package/dist/hooks/globalType.d.ts +2 -0
- package/dist/hooks/globalType.d.ts.map +1 -0
- package/dist/hooks/globalType.js +1 -0
- package/dist/hooks/useState.d.ts +1 -1
- package/dist/hooks/useState.d.ts.map +1 -1
- package/dist/hooks/useState.js +5 -5
- package/dist/hydrate/hydrate.d.ts +1 -1
- package/dist/hydrate/hydrate.d.ts.map +1 -1
- package/dist/hydrate/hydrate.js +159 -53
- package/dist/indexInner.d.ts +5 -3
- package/dist/indexInner.d.ts.map +1 -1
- package/dist/indexInner.js +5 -3
- package/dist/jsx-runtime.d.ts +2 -0
- package/dist/jsx-runtime.d.ts.map +1 -0
- package/dist/jsx-runtime.js +1 -0
- package/dist/jsxRuntime.d.ts +1 -1
- package/dist/jsxRuntime.d.ts.map +1 -1
- package/dist/jsxRuntime.js +10 -2
- package/dist/makeFinalConfig.d.ts.map +1 -1
- package/dist/makeInstanceConfigFromFrameworkConfig.d.ts +4 -0
- package/dist/makeInstanceConfigFromFrameworkConfig.d.ts.map +1 -0
- package/dist/makeInstanceConfigFromFrameworkConfig.js +12 -0
- package/dist/makeServerRpc.d.ts.map +1 -1
- package/dist/nbsp.d.ts +3 -0
- package/dist/nbsp.d.ts.map +1 -0
- package/dist/nbsp.js +8 -0
- package/dist/render/componentNodeToRenderingTree.d.ts +6 -0
- package/dist/render/componentNodeToRenderingTree.d.ts.map +1 -0
- package/dist/render/componentNodeToRenderingTree.js +41 -0
- package/dist/render/contentToHtml.d.ts +9 -0
- package/dist/render/contentToHtml.d.ts.map +1 -0
- package/dist/render/contentToHtml.js +44 -0
- package/dist/render/contentToHtmlDev.d.ts +9 -0
- package/dist/render/contentToHtmlDev.d.ts.map +1 -0
- package/dist/render/contentToHtmlDev.js +4 -0
- package/dist/render/contentTreeToRenderingTree.d.ts.map +1 -1
- package/dist/render/contentTreeToRenderingTree.js +8 -8
- package/dist/render/functionComponentNodeToRenderingTree.d.ts.map +1 -1
- package/dist/render/functionComponentNodeToRenderingTree.js +4 -2
- package/dist/render/instantiateClassComponent.d.ts +2 -2
- package/dist/render/instantiateClassComponent.d.ts.map +1 -1
- package/dist/render/instantiateClassComponent.js +1 -1
- package/dist/render/instantiateComponent.d.ts.map +1 -1
- package/dist/render/processProps.d.ts.map +1 -1
- package/dist/render/processProps.js +1 -1
- package/dist/render/renderingTreeToHtml.d.ts.map +1 -1
- package/dist/render/renderingTreeToHtml.js +42 -8
- package/dist/render/rootToHtml.d.ts +2 -1
- package/dist/render/rootToHtml.d.ts.map +1 -1
- package/dist/render/rootToHtml.js +12 -6
- package/dist/render/rootToHtmlDev.d.ts +4 -3
- package/dist/render/rootToHtmlDev.d.ts.map +1 -1
- package/dist/render/rootToHtmlDev.js +2 -2
- package/dist/routing/MatchedRoute.d.ts.map +1 -1
- package/dist/routing/MatchedRoute.js +0 -3
- package/dist/routing/runContentFunction.d.ts +2 -0
- package/dist/routing/runContentFunction.d.ts.map +1 -0
- package/dist/routing/runContentFunction.js +13 -0
- package/dist/staticGen/getAppRoutes.d.ts.map +1 -1
- package/dist/staticGen/getAppRoutes.js +7 -6
- package/dist/staticGen/staticGen.d.ts.map +1 -1
- package/dist/staticGen/staticGen.js +9 -1
- package/dist/update/integrateUpdateVdom.d.ts +13 -1
- package/dist/update/integrateUpdateVdom.d.ts.map +1 -1
- package/dist/update/integrateUpdateVdom.js +122 -61
- package/dist/update/integrateUpdateVdomPrebuild.d.ts +2 -0
- package/dist/update/integrateUpdateVdomPrebuild.d.ts.map +1 -0
- package/dist/update/integrateUpdateVdomPrebuild.js +1453 -0
- package/dist/validChildren.d.ts +4 -2
- package/dist/validChildren.d.ts.map +1 -1
- package/dist/validChildren.js +4 -0
- package/package.json +51 -45
- package/types/jsx/jsx.d.ts +10 -7
- package/dist/babelPlugins/BabelTransformCssImport.d.ts.map +0 -1
- package/dist/babelPlugins/BabelTransformCssImport.js +0 -80
- package/dist/babelPlugins/BabelTransformDependencyImportsCjs.d.ts.map +0 -1
- package/dist/babelPlugins/BabelTransformDependencyImportsEsm.d.ts.map +0 -1
- package/dist/babelPlugins/BabelTransformDependencyImportsEsm.js +0 -85
- package/dist/build/compileEnv.d.ts +0 -2
- package/dist/build/compileEnv.d.ts.map +0 -1
- package/dist/build/compileEnv.js +0 -132
- package/dist/build/createAppConfig.d.ts +0 -4
- package/dist/build/createAppConfig.d.ts.map +0 -1
- package/dist/build/webpack.user.prod.config.d.ts +0 -2
- package/dist/build/webpack.user.prod.config.d.ts.map +0 -1
- package/dist/build/webpack.user.prod.config.js +0 -337
- package/dist/createInstanceConfigFromFrameworkConfig.d.ts +0 -4
- package/dist/createInstanceConfigFromFrameworkConfig.d.ts.map +0 -1
- package/dist/createInstanceConfigFromFrameworkConfig.js +0 -9
- package/dist/getAppConfig.d.ts +0 -3
- package/dist/getAppConfig.d.ts.map +0 -1
- package/dist/getAppConfig.js +0 -12
- package/dist/render/componentNodeToRenderingToTree.d.ts +0 -6
- package/dist/render/componentNodeToRenderingToTree.d.ts.map +0 -1
- package/dist/render/componentNodeToRenderingToTree.js +0 -15
- package/dist/render/componentNodeToTree.d.ts +0 -5
- package/dist/render/componentNodeToTree.d.ts.map +0 -1
- package/dist/render/componentNodeToTree.js +0 -16
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import { join, dirname, relative } from 'path';
|
|
9
9
|
import slash from 'slash';
|
|
10
10
|
import precinct from 'precinct';
|
|
11
|
+
//import sxyPrecinct from 'sxy-precinct'
|
|
11
12
|
import cabinet from 'sxy-filing-cabinet';
|
|
12
13
|
import { existsSync, mkdirSync, promises as fsPromises, readFileSync, writeFileSync } from 'fs';
|
|
13
14
|
import { createRequire } from 'module';
|
|
@@ -18,11 +19,11 @@ const babelPluginSyntaxImportAssertions = babelPluginSyntaxImportAssertionsModul
|
|
|
18
19
|
import { init as lexerInit, parse as lexerParse } from 'cjs-module-lexer';
|
|
19
20
|
lexerInit();
|
|
20
21
|
import { MakeBabelTransformCjsToFunction } from "./BabelTransformCjsToFunction.js";
|
|
21
|
-
import { MakeBabelTransformDependencyImportsEsm } from "./BabelTransformDependencyImportsEsm.js";
|
|
22
|
-
import { MakeBabelTransformDependencyImportsCjs } from "./BabelTransformDependencyImportsCjs.js";
|
|
22
|
+
import { MakeBabelTransformDependencyImportsEsm } from "./transformPackageImports/BabelTransformDependencyImportsEsm.js";
|
|
23
|
+
import { MakeBabelTransformDependencyImportsCjs } from "./transformPackageImports/BabelTransformDependencyImportsCjs.js";
|
|
23
24
|
import { devBuildFolder, frameworkDistFolder, packageName as frameworkPackageName, packageName, packagesCacheFolder, packagesFolder /*, packagesCacheInfoName*/ } from "../settings.js";
|
|
24
25
|
import { findProjectDir } from "../findProjectDir.js";
|
|
25
|
-
import { cliError, cliWarn, cliNote } from "../cliOutput.js";
|
|
26
|
+
import { cliError, cliWarn, cliNote, cliInfo, cliNews } from "../cliOutput.js";
|
|
26
27
|
import { isBareImport } from "./isBareImport.js";
|
|
27
28
|
import { TungstenError } from "../TungstenError.js";
|
|
28
29
|
import { throwError } from "../throwError.js";
|
|
@@ -32,7 +33,15 @@ const require = createRequire(import.meta.url);
|
|
|
32
33
|
function debug(...texts) {
|
|
33
34
|
//console.log(...texts)
|
|
34
35
|
}
|
|
36
|
+
const javascriptFileExtensions = ['.js', '.jsx', '.cjs', '.cjsx', '.mjs', '.mjsx', '.ts', '.tsx', '.cts', '.ctx', '.mts', '.mtsx'];
|
|
37
|
+
function hasJavascriptFileExtension(file) {
|
|
38
|
+
for (const ex of javascriptFileExtensions) {
|
|
39
|
+
if (file.endsWith(ex)) return true;
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
35
43
|
export function MakeBabelTransformPackageImports(opts) {
|
|
44
|
+
//console.log('making BabelTransformPackageImports')
|
|
36
45
|
const buildLocation = join(opts.projectDir, devBuildFolder);
|
|
37
46
|
const packagesLocation = join(buildLocation, packagesFolder);
|
|
38
47
|
// get info about the packages cache
|
|
@@ -44,7 +53,7 @@ export function MakeBabelTransformPackageImports(opts) {
|
|
|
44
53
|
if (location.startsWith('./') || location.startsWith('../')) {
|
|
45
54
|
throw new TungstenError(`applyImportAliases() error: received a relative import, expected a bare import: ${location}`);
|
|
46
55
|
}
|
|
47
|
-
const segments = location.split('/');
|
|
56
|
+
const segments = location.split('/'); // as [string, string, ...string[]]
|
|
48
57
|
const [packageName, remaining] = location.startsWith('@') ? [segments[0] + '/' + segments[1], segments.slice(2).join('/')] : [segments[0], segments.slice(1).join('/')];
|
|
49
58
|
if (packageName === 'react') {
|
|
50
59
|
const sxyFrameworkBase = fileType === 'esm' ? 'tungsten/' : 'tungsten/sync/';
|
|
@@ -63,9 +72,18 @@ export function MakeBabelTransformPackageImports(opts) {
|
|
|
63
72
|
} else {
|
|
64
73
|
// aliases - at this point just redirecting react imports to tungsten
|
|
65
74
|
location = applyImportAliases(location, fileType);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
75
|
+
//cliNews(`trying to resolve ${location} from ${sourcePackageDir}`)
|
|
76
|
+
//cliOut(`sourceFile: ${sourceFile}`)
|
|
77
|
+
//cliInfo(`while processing: `)
|
|
78
|
+
let fullLocation;
|
|
79
|
+
try {
|
|
80
|
+
fullLocation = require.resolve(location, {
|
|
81
|
+
paths: [sourcePackageDir]
|
|
82
|
+
});
|
|
83
|
+
} catch (e) {
|
|
84
|
+
cliError(`BabelTransformPackageImports Error, failed to resolve ${location} from ${sourcePackageDir}`);
|
|
85
|
+
throw e;
|
|
86
|
+
}
|
|
69
87
|
if (fullLocation === location) {
|
|
70
88
|
return fullLocation;
|
|
71
89
|
}
|
|
@@ -87,8 +105,9 @@ export function MakeBabelTransformPackageImports(opts) {
|
|
|
87
105
|
};
|
|
88
106
|
const cjsRequireCache = {};
|
|
89
107
|
function getCjsRequire(file) {
|
|
90
|
-
|
|
91
|
-
|
|
108
|
+
const r = cjsRequireCache[file];
|
|
109
|
+
if (r !== undefined) {
|
|
110
|
+
return r;
|
|
92
111
|
} else {
|
|
93
112
|
return cjsRequireCache[file] = createRequire(file);
|
|
94
113
|
}
|
|
@@ -135,7 +154,7 @@ export function MakeBabelTransformPackageImports(opts) {
|
|
|
135
154
|
if (f === '') throw new TungstenError(`resolvePrecinctDependencies() err: cabinet returned empty string for ${dep} in ${packageDir}`);
|
|
136
155
|
out.push(f);
|
|
137
156
|
} catch (error) {
|
|
138
|
-
errorOut(`dependency lookup failed for dependency "${dep}" in file "${file}" originating in file ${sourceFilename}`);
|
|
157
|
+
errorOut(`dependency lookup failed for dependency "${dep}"` + ` in file "${file}" originating in file ${sourceFilename}`);
|
|
139
158
|
throw error;
|
|
140
159
|
}
|
|
141
160
|
}
|
|
@@ -172,7 +191,9 @@ export function MakeBabelTransformPackageImports(opts) {
|
|
|
172
191
|
}
|
|
173
192
|
}
|
|
174
193
|
const getPackageDirForFile = function getPackageDirForFile(file) {
|
|
175
|
-
|
|
194
|
+
const dir = getPackageDirForDir(dirname(file));
|
|
195
|
+
if (dir === undefined) throw new TungstenError(`MakeBabelTransformPackageImports Error: could not find package dir for file ${file}`);
|
|
196
|
+
return dir;
|
|
176
197
|
};
|
|
177
198
|
function packageIsEsm(packageJson) {
|
|
178
199
|
return packageJson.type === 'module';
|
|
@@ -180,8 +201,9 @@ export function MakeBabelTransformPackageImports(opts) {
|
|
|
180
201
|
const importedPackageLocations = {};
|
|
181
202
|
function getPackageInfo(packageDir) {
|
|
182
203
|
//console.log('getPackageInfo', packageDir)
|
|
183
|
-
|
|
184
|
-
|
|
204
|
+
const packageInfo = importedPackageLocations[packageDir];
|
|
205
|
+
if (packageInfo !== undefined) {
|
|
206
|
+
return packageInfo;
|
|
185
207
|
} else {
|
|
186
208
|
const packageJson = require(join(packageDir, 'package.json'));
|
|
187
209
|
const packageName = packageJson.name;
|
|
@@ -201,9 +223,10 @@ export function MakeBabelTransformPackageImports(opts) {
|
|
|
201
223
|
finalLocation
|
|
202
224
|
//dependencyPackagesInfo
|
|
203
225
|
};
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
226
|
+
const packageLogItem = packages[packageIdentifier];
|
|
227
|
+
if (packageLogItem !== undefined) {
|
|
228
|
+
if (packageLogItem.packageDir !== packageDir) {
|
|
229
|
+
cliWarn(`BabelTransformPackageImports found the same package in 2 different locations:` + `\n${packageLogItem.packageDir}` + `\nand\n${packageDir}`);
|
|
207
230
|
}
|
|
208
231
|
}
|
|
209
232
|
if (!(packageIdentifier in packages)) {
|
|
@@ -253,7 +276,7 @@ export function MakeBabelTransformPackageImports(opts) {
|
|
|
253
276
|
throw new TungstenError(`BabelTransformPackageImports error: sub file babel transform (1) returned null: ${file}`);
|
|
254
277
|
}
|
|
255
278
|
if (result.code === null || result.code === undefined) {
|
|
256
|
-
throw new TungstenError(`BabelTransformPackageImports error: sub file babel transform (1) returned code was null or undefined: ${typeof result.code}, ${file}`);
|
|
279
|
+
throw new TungstenError(`BabelTransformPackageImports error: sub file babel transform (1)` + ` returned code was null or undefined: ${typeof result.code}, ${file}`);
|
|
257
280
|
}
|
|
258
281
|
return result.code;
|
|
259
282
|
}
|
|
@@ -287,22 +310,24 @@ export function MakeBabelTransformPackageImports(opts) {
|
|
|
287
310
|
throw new TungstenError(`BabelTransformPackageImports error: sub file babel transform (2) returned null: ${file}`);
|
|
288
311
|
}
|
|
289
312
|
if (result.code === null || result.code === undefined) {
|
|
290
|
-
throw new TungstenError(`BabelTransformPackageImports error: sub file babel transform (2) returned code was null or undefined: ${typeof result.code}, ${file}`);
|
|
313
|
+
throw new TungstenError(`BabelTransformPackageImports error: sub file babel transform (2)` + ` returned code was null or undefined: ${typeof result.code}, ${file}`);
|
|
291
314
|
}
|
|
292
315
|
const intermedCacheLocation = getFileEsmGenIntermediateCacheLocation(file, packageInfo);
|
|
293
316
|
await fsPromises.mkdir(dirname(intermedCacheLocation), {
|
|
294
317
|
recursive: true
|
|
295
318
|
});
|
|
319
|
+
//console.log('writing file', intermedCacheLocation)
|
|
296
320
|
await fsPromises.writeFile(intermedCacheLocation, result.code); // rel contains the slash at start
|
|
297
321
|
result = await babelTransformAsync(result.code, {
|
|
298
322
|
filename: file,
|
|
299
323
|
...makeModifyImportsCjsBabelOptions(nonEsmDepsWebPath)
|
|
300
324
|
});
|
|
301
325
|
if (result === null) {
|
|
302
|
-
throw new TungstenError(`BabelTransformPackageImports error: sub file babel transform (3) returned null: ${file}
|
|
326
|
+
throw new TungstenError(`BabelTransformPackageImports error: sub file babel transform (3) returned null: ${file}
|
|
327
|
+
`);
|
|
303
328
|
}
|
|
304
329
|
if (result.code === null || result.code === undefined) {
|
|
305
|
-
throw new TungstenError(`BabelTransformPackageImports error: sub file babel transform (3) returned code was null or undefined: ${typeof result.code}, ${file}`);
|
|
330
|
+
throw new TungstenError(`BabelTransformPackageImports error: sub file babel transform (3)` + ` returned code was null or undefined: ${typeof result.code}, ${file}`);
|
|
306
331
|
}
|
|
307
332
|
//if (file.includes('domexception')) console.log('transformed imports', code)
|
|
308
333
|
return result.code;
|
|
@@ -368,17 +393,37 @@ export function MakeBabelTransformPackageImports(opts) {
|
|
|
368
393
|
recursive: true
|
|
369
394
|
});
|
|
370
395
|
//if (file.endsWith('index.cjs')) console.log('checking type for *index.cjs file:', packageInfo.type)
|
|
371
|
-
if (
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
396
|
+
if (hasJavascriptFileExtension(file)) {
|
|
397
|
+
if (packageInfo.type === 'esm' && file.endsWith('.js') || file.endsWith('.mjs')) {
|
|
398
|
+
try {
|
|
399
|
+
const code = await babelFileEsm(file /*, packageInfo*/, nonEsmDependenciesFull);
|
|
400
|
+
//console.log('writing file', cacheDest)
|
|
401
|
+
//console.log('writing file', finalDest)
|
|
402
|
+
await fsPromises.writeFile(cacheDest, code); // rel contains the slash at start
|
|
403
|
+
await fsPromises.writeFile(finalDest, code); // rel contains the slash at start
|
|
404
|
+
} catch (e) {
|
|
405
|
+
cliError(`Error transforming file '${file}' with bableFileEsm`);
|
|
406
|
+
throw e;
|
|
407
|
+
}
|
|
408
|
+
} else {
|
|
409
|
+
try {
|
|
410
|
+
//if (file.endsWith('index.cjs')) console.log('trying to transform a *index.cjs file:', file)
|
|
411
|
+
const code = await babelFileCjs(file, cacheDest, finalDest, packageInfo, nonEsmDependenciesFull);
|
|
412
|
+
//console.log('writing file', cacheDest)
|
|
413
|
+
//console.log('writing file', finalDest)
|
|
414
|
+
//if (file.endsWith('index.cjs')) console.log('writing a transformed *index.cjs file to cache:', cacheDest)
|
|
415
|
+
await fsPromises.writeFile(cacheDest, code); // rel contains the slash at start
|
|
416
|
+
//if (file.endsWith('index.cjs')) console.log('writing a transformed *index.cjs file to final:', finalDest)
|
|
417
|
+
await fsPromises.writeFile(finalDest, code); // rel contains the slash at start
|
|
418
|
+
} catch (e) {
|
|
419
|
+
cliError(`Error transforming file '${file}' with babelFileCjs`);
|
|
420
|
+
throw e;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
375
423
|
} else {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
await fsPromises.writeFile(cacheDest, code); // rel contains the slash at start
|
|
380
|
-
//if (file.endsWith('index.cjs')) console.log('writing a transformed *index.cjs file to final:', finalDest)
|
|
381
|
-
await fsPromises.writeFile(finalDest, code); // rel contains the slash at start
|
|
424
|
+
cliInfo(`copying package file ${file}`);
|
|
425
|
+
await fsPromises.copyFile(file, cacheDest);
|
|
426
|
+
await fsPromises.copyFile(file, finalDest);
|
|
382
427
|
}
|
|
383
428
|
const dependenciesFileIndentifiers = dependenciesFull.map(d => d.fileIdentifier);
|
|
384
429
|
addToDependencyGraphFromFileInfo(fileInfo, dependenciesFileIndentifiers);
|
|
@@ -405,14 +450,15 @@ export function MakeBabelTransformPackageImports(opts) {
|
|
|
405
450
|
}
|
|
406
451
|
async function processCacheDependencies(dependencies) {
|
|
407
452
|
for (const dep of dependencies) {
|
|
408
|
-
|
|
453
|
+
const cacheNode = opts.oldDependencyGraph[dep];
|
|
454
|
+
if (cacheNode === undefined) {
|
|
409
455
|
throw new TungstenError(`processCacheDependencies() Error: ${dep} not found in existing dependency graph`);
|
|
410
456
|
}
|
|
411
|
-
const cacheNode = opts.oldDependencyGraph[dep]
|
|
457
|
+
//const cacheNode = opts.oldDependencyGraph[dep]
|
|
412
458
|
if (existsSync(cacheNode.originalLocation)) {
|
|
413
459
|
await copyFileFromCache(dep, cacheNode);
|
|
414
460
|
} else {
|
|
415
|
-
throw new TungstenError(`processCacheDependencies() Error: source file ${cacheNode.originalLocation} for ${dep} does not exist
|
|
461
|
+
throw new TungstenError(`processCacheDependencies() Error: source file ${cacheNode.originalLocation}` + ` for ${dep} does not exist.` + ` Perhaps the package version was increased, and we need to process anew`);
|
|
416
462
|
// find the import/require specification
|
|
417
463
|
// resolve with sxy-filing-cabinet
|
|
418
464
|
// resolveFile
|
|
@@ -508,8 +554,9 @@ export function MakeBabelTransformPackageImports(opts) {
|
|
|
508
554
|
const lexInnerCache = {};
|
|
509
555
|
function lexInternal(file) {
|
|
510
556
|
const cache = lexInnerCache;
|
|
511
|
-
|
|
512
|
-
|
|
557
|
+
const result = cache[file];
|
|
558
|
+
if (result !== undefined) {
|
|
559
|
+
return result;
|
|
513
560
|
} else {
|
|
514
561
|
const code = readFileSync(file, 'utf8');
|
|
515
562
|
const {
|
|
@@ -532,8 +579,9 @@ export function MakeBabelTransformPackageImports(opts) {
|
|
|
532
579
|
const makeCjsEntryFile = function makeCjsEntryFile(orginalFile, newLocationSiteRel) {
|
|
533
580
|
//console.log('makeCjsEntryFile', 'orginalFile', orginalFile, 'newLocationSiteRel', newLocationSiteRel)
|
|
534
581
|
const cache = makeCjsEntryFileCache;
|
|
535
|
-
|
|
536
|
-
|
|
582
|
+
const result = cache[newLocationSiteRel];
|
|
583
|
+
if (result !== undefined) {
|
|
584
|
+
return result;
|
|
537
585
|
} else {
|
|
538
586
|
const entryFile = newLocationSiteRel.slice(0, newLocationSiteRel.lastIndexOf('.')) + '.sxy-entry.js';
|
|
539
587
|
const entryFileAbs = join(buildLocation, entryFile);
|
|
@@ -587,7 +635,8 @@ export function MakeBabelTransformPackageImports(opts) {
|
|
|
587
635
|
return {
|
|
588
636
|
pre(state) {
|
|
589
637
|
filename = slash(state.opts.filename);
|
|
590
|
-
//
|
|
638
|
+
//cliWarn('process package imports', filename)
|
|
639
|
+
//cliWarn('BabelTransformPackageImports on', filename)
|
|
591
640
|
const relativeFilename = filename.slice(opts.codeDir.length + 1);
|
|
592
641
|
destinationFilename = join(buildLocation, relativeFilename);
|
|
593
642
|
//console.log('filename', filename, 'destinationFilename', destinationFilename)
|
|
@@ -603,6 +652,9 @@ export function MakeBabelTransformPackageImports(opts) {
|
|
|
603
652
|
if (isBareImport(location)) {
|
|
604
653
|
//if (location.startsWith('@')) console.log('import starts with @', location)
|
|
605
654
|
//console.log(chalk.blue('Bare PackageImport found'), location, 'from', filename)
|
|
655
|
+
if (location.includes("range-slider")) {
|
|
656
|
+
cliNews(`package import ${location}`);
|
|
657
|
+
}
|
|
606
658
|
// if ('location'.startsWith('node:')) {
|
|
607
659
|
// throwError('BabelTransformPackageImports', 'Found an import to a node package in user code.')
|
|
608
660
|
// }
|
|
@@ -640,16 +692,28 @@ export function MakeBabelTransformPackageImports(opts) {
|
|
|
640
692
|
//// location relative to this file
|
|
641
693
|
// relative assumes to source to be a dir, so use only the dirname not the full path
|
|
642
694
|
let newLocationRelative = relative(dirname(destinationFilename), finalDest);
|
|
643
|
-
if (!newLocationRelative.startsWith('../'))
|
|
695
|
+
if (!newLocationRelative.startsWith('../')) {
|
|
696
|
+
newLocationRelative = './' + newLocationRelative;
|
|
697
|
+
}
|
|
644
698
|
//console.log('bare import type', type)
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
699
|
+
//cliAlert(`Finalising ${importTarget}`)
|
|
700
|
+
if (hasJavascriptFileExtension(importTarget)) {
|
|
701
|
+
if (type === 'esm') {
|
|
702
|
+
addImportAlias(location, webLocation);
|
|
703
|
+
//console.log('add alias for', location)
|
|
704
|
+
} else {
|
|
705
|
+
const entryFile = makeCjsEntryFile(sourceFile, webLocation);
|
|
706
|
+
addImportAlias(location, entryFile);
|
|
707
|
+
//console.log('add alias for', location)
|
|
708
|
+
}
|
|
648
709
|
} else {
|
|
649
|
-
|
|
650
|
-
addImportAlias(location,
|
|
651
|
-
//console.log('add alias for', location)
|
|
710
|
+
path.node.source.value = webLocation;
|
|
711
|
+
//addImportAlias(location, webLocation)
|
|
652
712
|
}
|
|
713
|
+
// else {
|
|
714
|
+
// cliInfo(`Removing`, path)
|
|
715
|
+
// path.remove()
|
|
716
|
+
// }
|
|
653
717
|
}
|
|
654
718
|
} catch (e) {
|
|
655
719
|
//(() => {})()
|
|
@@ -668,6 +732,7 @@ export function MakeBabelTransformPackageImports(opts) {
|
|
|
668
732
|
// }
|
|
669
733
|
},
|
|
670
734
|
post() {
|
|
735
|
+
//cliWarn('Finished BabelTransformPackageImports on', filename)
|
|
671
736
|
//promises.push(destinationFilename)
|
|
672
737
|
//console.log(promises)
|
|
673
738
|
//setTimeout(() => console.log('post'), 0)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BabelTransformReactive.d.ts","sourceRoot":"","sources":["../../src/babelPlugins/BabelTransformReactive.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,KAAK,EAAQ,QAAQ,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AA+CnE,MAAM,CAAC,OAAO,UAAU,sBAAsB,
|
|
1
|
+
{"version":3,"file":"BabelTransformReactive.d.ts","sourceRoot":"","sources":["../../src/babelPlugins/BabelTransformReactive.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,KAAK,EAAQ,QAAQ,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AA+CnE,MAAM,CAAC,OAAO,UAAU,sBAAsB,KACP,OAAO,KAAK;;;;;wBA0BnB,QAAQ,CAAC,cAAc,CAAC,SAAS,GAAG;uBAwBrC,QAAQ,CAAC,cAAc,CAAC,SAAS,GAAG;;+BAwC5B,QAAQ,CAAC,gBAAgB,CAAC,SAAS,GAAG;;EA+B5E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BabelTransformReactiveSvelteStyle.d.ts","sourceRoot":"","sources":["../../src/babelPlugins/BabelTransformReactiveSvelteStyle.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,KAAK,EAAQ,QAAQ,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAavD,MAAM,CAAC,OAAO,UAAU,sBAAsB,
|
|
1
|
+
{"version":3,"file":"BabelTransformReactiveSvelteStyle.d.ts","sourceRoot":"","sources":["../../src/babelPlugins/BabelTransformReactiveSvelteStyle.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,KAAK,EAAQ,QAAQ,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAavD,MAAM,CAAC,OAAO,UAAU,sBAAsB,KACP,OAAO,KAAK;;;mCAKR,QAAQ,CAAC,oBAAoB,CAAC,SAAS,GAAG;;EAmCpF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BabelTransformRemoveServerBlocks.d.ts","sourceRoot":"","sources":["../../src/babelPlugins/BabelTransformRemoveServerBlocks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,EAAE,qBAAqB,EAAc,WAAW,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"BabelTransformRemoveServerBlocks.d.ts","sourceRoot":"","sources":["../../src/babelPlugins/BabelTransformRemoveServerBlocks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,EAAE,qBAAqB,EAAc,WAAW,EAAE,MAAM,aAAa,CAAA;AASjF,wBAAgB,oCAAoC;;0BAgBlB,QAAQ,CAAC,WAAW,CAAC;oCAWX,QAAQ,CAAC,qBAAqB,CAAC;;EAS1E"}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
//////////////////////////////////////
|
|
2
|
+
//////////////////////////////////////
|
|
3
|
+
// TODO: Remove serverInit functions
|
|
4
|
+
//////////////////////////////////////
|
|
5
|
+
//////////////////////////////////////
|
|
1
6
|
export function MakeBabelTransformRemoveServerBlocks() {
|
|
2
7
|
return function BabelTransformRemoveServerBlocks(/*babel*/
|
|
3
8
|
) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BabelTransformRemoveServerCode.d.ts","sourceRoot":"","sources":["../../src/babelPlugins/BabelTransformRemoveServerCode.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BabelTransformUniqueComponents.d.ts","sourceRoot":"","sources":["../../src/babelPlugins/BabelTransformUniqueComponents.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAc5C,MAAM,CAAC,OAAO,UAAU,kCAAkC,
|
|
1
|
+
{"version":3,"file":"BabelTransformUniqueComponents.d.ts","sourceRoot":"","sources":["../../src/babelPlugins/BabelTransformUniqueComponents.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAc5C,MAAM,CAAC,OAAO,UAAU,kCAAkC,KACP,OAAO,KAAK;;gCAOvB,QAAQ,CAAC,KAAK,CAAC,iBAAiB,CAAC;;EAwBxE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fixImportsInSassErrorMessage.d.ts","sourceRoot":"","sources":["../../src/babelPlugins/fixImportsInSassErrorMessage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAA;AAazE,KAAK,kCAAkC,GAAG;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,OAAO,CAAA;CAC5B,CAAA;AAED,wBAAgB,4BAA4B,
|
|
1
|
+
{"version":3,"file":"fixImportsInSassErrorMessage.d.ts","sourceRoot":"","sources":["../../src/babelPlugins/fixImportsInSassErrorMessage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAA;AAazE,KAAK,kCAAkC,GAAG;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,OAAO,CAAA;CAC5B,CAAA;AAED,wBAAgB,4BAA4B,CACxC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,oBAAoB,EAAE,GAC7C,kCAAkC,CAsFpC"}
|
|
@@ -2,7 +2,7 @@ import type * as BabelCore from '@babel/core';
|
|
|
2
2
|
import { NodePath } from '@babel/core';
|
|
3
3
|
type Babel = typeof BabelCore;
|
|
4
4
|
import { ExportAllDeclaration, ExportNamedDeclaration, type CallExpression, type ImportDeclaration } from 'babel-types';
|
|
5
|
-
import type { GetPackageDirForFile, GetPackageInfoForFile, GetExternalImportFinalImportLocation, GetCjsRelativeImportFinalImportLocation, GetFileFinalLocation } from '
|
|
5
|
+
import type { GetPackageDirForFile, GetPackageInfoForFile, GetExternalImportFinalImportLocation, GetCjsRelativeImportFinalImportLocation, GetFileFinalLocation } from '../BabelTransformPackageImports.js';
|
|
6
6
|
type Opts = {
|
|
7
7
|
nonEsmDeps: string[];
|
|
8
8
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BabelTransformDependencyImportsCjs.d.ts","sourceRoot":"","sources":["../../../src/babelPlugins/transformPackageImports/BabelTransformDependencyImportsCjs.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,KAAK,SAAS,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAc,MAAM,aAAa,CAAA;AAClD,KAAK,KAAK,GAAG,OAAO,SAAS,CAAC;AAM9B,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAA0B,KAAK,cAAc,EAAmB,KAAK,iBAAiB,EAAsB,MAAM,aAAa,CAAA;AAIpL,OAAO,KAAK,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,oCAAoC,EAAE,uCAAuC,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAA;AAU1M,KAAK,IAAI,GAAG;IACR,UAAU,EAAE,MAAM,EAAE,CAAA;CACvB,CAAA;AAED,KAAK,KAAK,GAAG;IACT,oBAAoB,EAAE,oBAAoB,CAAA;IAC1C,qBAAqB,EAAE,qBAAqB,CAAA;IAC5C,oCAAoC,EAAE,oCAAoC,CAAA;IAC1E,uCAAuC,EAAE,uCAAuC,CAAA;IAChF,oBAAoB,EAAE,oBAAoB,CAAA;CAC7C,CAAA;AAED,wBAAgB,sCAAsC,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,IACxB,OAAO,KAAK;eAoC5C,GAAG;;kCAQyB,QAAQ,CAAC,iBAAiB,CAAC;uCAKtB,QAAQ,CAAC,sBAAsB,CAAC;qCAOlC,QAAQ,CAAC,oBAAoB,CAAC;6BAO/C,QAAQ,CAAC,cAAc,CAAC;;EAgE5D"}
|
|
@@ -9,9 +9,10 @@
|
|
|
9
9
|
// }
|
|
10
10
|
import { dirname, relative } from 'path';
|
|
11
11
|
import slash from 'slash';
|
|
12
|
-
import { isBareImport } from "
|
|
13
|
-
import { cliWarn } from "
|
|
14
|
-
import { warn } from "
|
|
12
|
+
import { isBareImport } from "../isBareImport.js";
|
|
13
|
+
import { cliWarn } from "../../cliOutput.js";
|
|
14
|
+
import { warn } from "../../output.js";
|
|
15
|
+
import { TungstenError } from 'tungsten/TungstenError.js';
|
|
15
16
|
export function MakeBabelTransformDependencyImportsCjs(opts, funcs) {
|
|
16
17
|
return function BabelTransformDependencyImportsCjs(babel) {
|
|
17
18
|
const t = babel.types;
|
|
@@ -82,6 +83,9 @@ export function MakeBabelTransformDependencyImportsCjs(opts, funcs) {
|
|
|
82
83
|
//console.log('import call ex', path.node)
|
|
83
84
|
const arg0 = path.node.arguments[0];
|
|
84
85
|
//console.log('first arg', arg0)
|
|
86
|
+
if (arg0 === undefined) {
|
|
87
|
+
throw new TungstenError(`BabelTransformDependencyImportsCjs Error: no arg0 of CallExpression`);
|
|
88
|
+
}
|
|
85
89
|
if (arg0.type === 'StringLiteral') {
|
|
86
90
|
const location = arg0.value;
|
|
87
91
|
const [transform, newLocation] = getNewLocation(location);
|
|
@@ -96,6 +100,9 @@ export function MakeBabelTransformDependencyImportsCjs(opts, funcs) {
|
|
|
96
100
|
//console.log('require call ex', path.node)
|
|
97
101
|
const arg0 = path.node.arguments[0];
|
|
98
102
|
//console.log('first arg', arg0)
|
|
103
|
+
if (arg0 === undefined) {
|
|
104
|
+
throw new TungstenError(`BabelTransformDependencyImportsCjs Error: no arg0 of CallExpression`);
|
|
105
|
+
}
|
|
99
106
|
if (arg0.type === 'StringLiteral') {
|
|
100
107
|
const location = arg0.value;
|
|
101
108
|
//console.log(chalk.red`found a require`, location)
|
|
@@ -2,7 +2,7 @@ import type * as BabelCore from '@babel/core';
|
|
|
2
2
|
import { NodePath } from '@babel/core';
|
|
3
3
|
type Babel = typeof BabelCore;
|
|
4
4
|
import { CallExpression, ExportAllDeclaration, ExportNamedDeclaration, ImportDeclaration } from '@babel/types';
|
|
5
|
-
import type { GetPackageDirForFile, GetPackageInfoForFile, GetExternalImportFinalImportLocation, GetFileFinalLocation, MakeCjsEntryFile } from '
|
|
5
|
+
import type { GetPackageDirForFile, GetPackageInfoForFile, GetExternalImportFinalImportLocation, GetFileFinalLocation, MakeCjsEntryFile } from '../BabelTransformPackageImports.js';
|
|
6
6
|
type Opts = {
|
|
7
7
|
nonEsmDeps: string[];
|
|
8
8
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BabelTransformDependencyImportsEsm.d.ts","sourceRoot":"","sources":["../../../src/babelPlugins/transformPackageImports/BabelTransformDependencyImportsEsm.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,KAAK,SAAS,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAc,MAAM,aAAa,CAAA;AAClD,KAAK,KAAK,GAAG,OAAO,SAAS,CAAC;AAO9B,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAI9G,OAAO,KAAK,EACR,oBAAoB,EAAE,qBAAqB,EAAE,oCAAoC,EACjF,oBAAoB,EAAE,gBAAgB,EACzC,MAAM,oCAAoC,CAAA;AAM3C,KAAK,IAAI,GAAG;IACR,UAAU,EAAE,MAAM,EAAE,CAAA;CACvB,CAAA;AAED,KAAK,KAAK,GAAG;IACT,oBAAoB,EAAE,oBAAoB,CAAA;IAC1C,qBAAqB,EAAE,qBAAqB,CAAA;IAC5C,oCAAoC,EAAE,oCAAoC,CAAA;IAC1E,oBAAoB,EAAE,oBAAoB,CAAA;IAC1C,gBAAgB,EAAE,gBAAgB,CAAA;CACrC,CAAA;AAED,wBAAgB,sCAAsC,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,IACxB,OAAO,KAAK;eA0B5C,GAAG;;gCAOc,QAAQ,CAAC,iBAAiB,CAAC;uCAYX,QAAQ,CAAC,sBAAsB,CAAC;qCAalC,QAAQ,CAAC,oBAAoB,CAAC;6BAa/C,QAAQ,CAAC,cAAc,CAAC;;EAiC5D"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// BabelTransformDependencyImportsEsm
|
|
2
|
+
// exports MakeBabelTransformDependencyImportsEsm (function)/
|
|
3
|
+
// Arg 1: opts {
|
|
4
|
+
// nonEsmDeps: string[] (should it be an obj?) -- a list of CJS/presumed CJS direct dependencies to let us switch between ESM (defualt) and CJS handling
|
|
5
|
+
// }
|
|
6
|
+
// Arg 2: funcs {
|
|
7
|
+
// funcs from the parent to do various things.
|
|
8
|
+
// passed in from the parent because this allows them to use a central cache
|
|
9
|
+
// }
|
|
10
|
+
import { dirname, relative } from 'path';
|
|
11
|
+
import slash from 'slash';
|
|
12
|
+
import { isBareImport } from "../isBareImport.js";
|
|
13
|
+
import { throwError } from 'tungsten/throwError.js';
|
|
14
|
+
import { cliError, cliOut } from 'tungsten/cliOutput.js';
|
|
15
|
+
export function MakeBabelTransformDependencyImportsEsm(opts, funcs) {
|
|
16
|
+
return function BabelTransformDependencyImportsEsm(babel) {
|
|
17
|
+
const t = babel.types;
|
|
18
|
+
let filename;
|
|
19
|
+
let futureFilename;
|
|
20
|
+
let packageDir;
|
|
21
|
+
function getNewLocation(location) {
|
|
22
|
+
//console.log('BabelTransformDependencyImportsEsm', 'getNewLocation', location, filename)
|
|
23
|
+
if (isBareImport(location)) {
|
|
24
|
+
//cliNews('BabelTransformDependencyImportsEsm')
|
|
25
|
+
//cliOut(filename)
|
|
26
|
+
const final = funcs.getExternalImportFinalImportLocation(location, filename, packageDir, 'esm');
|
|
27
|
+
if (final === location) {
|
|
28
|
+
// do we need this anymore?
|
|
29
|
+
//cliNote('calculated final location is the same as the original', location)
|
|
30
|
+
// perhaps a node module
|
|
31
|
+
return [false];
|
|
32
|
+
}
|
|
33
|
+
let rel = slash(relative(dirname(futureFilename), final));
|
|
34
|
+
if (!rel.startsWith('../')) rel = './' + rel;
|
|
35
|
+
return [true, rel];
|
|
36
|
+
} else {
|
|
37
|
+
return [false];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
pre(state) {
|
|
42
|
+
filename = state.opts.filename;
|
|
43
|
+
const packageInfo = funcs.getPackageInfoForFile(filename);
|
|
44
|
+
packageDir = packageInfo.packageDir;
|
|
45
|
+
futureFilename = funcs.getFileFinalLocation(filename, packageInfo);
|
|
46
|
+
},
|
|
47
|
+
visitor: {
|
|
48
|
+
ImportDeclaration(path) {
|
|
49
|
+
try {
|
|
50
|
+
const location = path.node.source.value;
|
|
51
|
+
//console.log('BabelTransformDependencyImportsEsm', 'ImportDeclaration', path.node)
|
|
52
|
+
const [transform, newLocation] = getNewLocation(location);
|
|
53
|
+
if (transform) path.node.source.value = newLocation;
|
|
54
|
+
} catch (e) {
|
|
55
|
+
cliError(`Error in BabelTransformDependencyImportsEsm->ImportDeclaration`);
|
|
56
|
+
cliOut(e.stack);
|
|
57
|
+
throw e;
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
ExportNamedDeclaration: function (path) {
|
|
61
|
+
try {
|
|
62
|
+
if (path.node.source) {
|
|
63
|
+
const location = path.node.source.value;
|
|
64
|
+
const [transform, newLocation] = getNewLocation(location);
|
|
65
|
+
if (transform) path.node.source.value = newLocation;
|
|
66
|
+
}
|
|
67
|
+
} catch (e) {
|
|
68
|
+
cliError(`Error in BabelTransformDependencyImportsEsm->ExportNamedDeclaration`);
|
|
69
|
+
cliOut(e.stack);
|
|
70
|
+
throw e;
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
ExportAllDeclaration: function (path) {
|
|
74
|
+
try {
|
|
75
|
+
if (path.node.source) {
|
|
76
|
+
const location = path.node.source.value;
|
|
77
|
+
const [transform, newLocation] = getNewLocation(location);
|
|
78
|
+
if (transform) path.node.source.value = newLocation;
|
|
79
|
+
}
|
|
80
|
+
} catch (e) {
|
|
81
|
+
cliError(`Error in BabelTransformDependencyImportsEsm->ExportAllDeclaration`);
|
|
82
|
+
cliOut(e.stack);
|
|
83
|
+
throw e;
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
CallExpression(path) {
|
|
87
|
+
try {
|
|
88
|
+
if (path.node.callee.type === 'Import') {
|
|
89
|
+
const firstArg = path.node.arguments[0];
|
|
90
|
+
if (firstArg) {
|
|
91
|
+
if (firstArg.type === 'StringLiteral') {
|
|
92
|
+
const location = firstArg.value;
|
|
93
|
+
//console.log('BabelTransformDependencyImportsEsm', 'CallExpression', path.node)
|
|
94
|
+
const [transform, newLocation] = getNewLocation(location);
|
|
95
|
+
if (transform) path.node.arguments[0] = t.stringLiteral(newLocation);
|
|
96
|
+
} else {
|
|
97
|
+
throwError(`BabelTransformDependencyImportsEsm`, `The first argument passed to an import call in file ${filename}` + ` was a ${firstArg.type}, we we were expecting a StringLiteral.` + ` Only static imports can be processed. This file was found in the` + ` dependency chain of your Tungsten app, was this a mistake?`);
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
throwError(`BabelTransformDependencyImportsEsm`, `No args were passed to an import call being processed in file ${filename}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
} catch (e) {
|
|
104
|
+
cliError(`Error in BabelTransformDependencyImportsEsm->CallExpression`);
|
|
105
|
+
cliOut(e.stack);
|
|
106
|
+
throw e;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getWebLocationOfPackageFile.d.ts","sourceRoot":"","sources":["../../../src/babelPlugins/transformPackageImports/getWebLocationOfPackageFile.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { dirname } from 'path';
|
|
2
|
+
import { TungstenError } from "../../TungstenError.js";
|
|
3
|
+
import { findProjectDir } from "../../findProjectDir.js";
|
|
4
|
+
const getPackageDirForDirCache = {};
|
|
5
|
+
function getPackageDirForDir(dir) {
|
|
6
|
+
if (dir in getPackageDirForDirCache) {
|
|
7
|
+
return getPackageDirForDirCache[dir];
|
|
8
|
+
} else {
|
|
9
|
+
return getPackageDirForDirCache[dir] = findProjectDir(dir);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function getPackageDirForFile(file) {
|
|
13
|
+
const dir = getPackageDirForDir(dirname(file));
|
|
14
|
+
if (dir === undefined) throw new TungstenError(`MakeBabelTransformPackageImports Error: could not find package dir for file ${file}`);
|
|
15
|
+
return dir;
|
|
16
|
+
}
|
|
17
|
+
// function getWebLocationOfPackageFile(file: string): string {
|
|
18
|
+
// //console.log('resolve file', file)
|
|
19
|
+
// const packageDir = getPackageDirForFile(file)
|
|
20
|
+
// const relFile = file.slice(packageDir.length + 1)
|
|
21
|
+
// const fileIdentifier = `${packageInfo.packageIdentifier}/${slash(relFile)}`
|
|
22
|
+
// const cacheDest = join(packageInfo.cacheLocation, relFile)
|
|
23
|
+
// const finalDest = join(packageInfo.finalLocation, relFile)
|
|
24
|
+
// const webLocation = `/${packagesFolder}/${packageInfo.packageIdentifier}/${slash(relFile)}`
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compileSimplePackage.d.ts","sourceRoot":"","sources":["../../../src/bin/commands/compileSimplePackage.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { findProjectDir } from "../../findProjectDir.js";
|
|
2
|
+
import { cliInfo, cliLog } from "../../cliOutput.js";
|
|
3
|
+
cliInfo('tungsten compile-simple-package is not ready yet');
|
|
4
|
+
process.exit(2);
|
|
5
|
+
const projectDir = process.cwd();
|
|
6
|
+
const frameworkDir = findProjectDir(import.meta.url);
|
|
7
|
+
const args = process.argv.slice(3);
|
|
8
|
+
const source = args[0];
|
|
9
|
+
const dest = args[1];
|
|
10
|
+
console.log(typeof source, source);
|
|
11
|
+
console.log(typeof dest, dest);
|
|
12
|
+
if (typeof dest === 'undefined') {
|
|
13
|
+
cliInfo(`Usage: tungsten compile-simple-package <sourceFolder> <destFolder>`);
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
import babelPresetReactModule from '@babel/preset-react';
|
|
17
|
+
const babelPresetReact = babelPresetReactModule.default;
|
|
18
|
+
// const babelConfig: TransformOptions = {
|
|
19
|
+
// presets: [
|
|
20
|
+
// [babelPresetReact, {
|
|
21
|
+
// 'runtime': 'automatic',
|
|
22
|
+
// 'importSource': 'tungsten',
|
|
23
|
+
// }],
|
|
24
|
+
// ],
|
|
25
|
+
// plugins: [
|
|
26
|
+
// [babelPluginSxyModuleResolve, {
|
|
27
|
+
// 'alias': {
|
|
28
|
+
// 'tungsten/jsx-runtime': 'tungsten/jsxRuntime.js' // fix the import location created by @babel/preset-react
|
|
29
|
+
// }
|
|
30
|
+
// }],
|
|
31
|
+
// MakeBabelTransformJsxExtensionsToJs(),
|
|
32
|
+
// [babelPluginCassToJs],
|
|
33
|
+
// [babelPluginProposalClassProperties],
|
|
34
|
+
// ],
|
|
35
|
+
// 'env': {
|
|
36
|
+
// 'production': {
|
|
37
|
+
// 'plugins': ['transform-react-remove-prop-types']
|
|
38
|
+
// }
|
|
39
|
+
// }
|
|
40
|
+
// }
|
|
41
|
+
const command = 'cross-env NODE_ENV=production babel js/lib --config-file ./build.babel.config.json --out-dir dist-react --copy-files';
|
|
42
|
+
cliLog('compile command:', command);
|
|
43
|
+
// const subProcess = spawnShellCommand(command, { cwd: projectDir /*cwd: projectDir*//*, stdio: 'inherit'*/ })
|
|
44
|
+
// subProcess.on('data', (data) => cliLog(data))
|
|
45
|
+
// subProcess.on('close', (code, message) => {
|
|
46
|
+
// if (code === 0) {
|
|
47
|
+
// cliLog('Compilation complete')
|
|
48
|
+
// } else {
|
|
49
|
+
// cliError(`Compilation process failed with code ${code}, message "${message}"`)
|
|
50
|
+
// }
|
|
51
|
+
// })
|