tungsten 0.4.2 → 0.4.4
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/.build-complete +1 -1
- package/dist/Framework.d.ts +1 -0
- package/dist/Framework.d.ts.map +1 -1
- package/dist/Framework.js +15 -10
- package/dist/bin/commands/build.d.ts.map +1 -1
- package/dist/bin/commands/build.js +9 -6
- package/dist/bin/commands/buildHelp.d.ts +2 -0
- package/dist/bin/commands/buildHelp.d.ts.map +1 -0
- package/dist/bin/commands/buildHelp.js +7 -0
- package/dist/bin/commands/help.d.ts +2 -0
- package/dist/bin/commands/help.d.ts.map +1 -0
- package/dist/bin/commands/help.js +16 -0
- package/dist/bin/index.d.ts.map +1 -1
- package/dist/bin/index.js +17 -5
- package/dist/build/bundle.d.ts +1 -1
- package/dist/build/bundle.d.ts.map +1 -1
- package/dist/build/bundle.js +6 -4
- package/dist/componentCss/tungsten.css +2 -2
- package/dist/staticGen/getAppRoutes.d.ts +1 -1
- package/dist/staticGen/getAppRoutes.d.ts.map +1 -1
- package/dist/staticGen/getAppRoutes.js +10 -7
- package/dist/staticGen/staticGen.d.ts.map +1 -1
- package/dist/staticGen/staticGen.js +6 -5
- package/dist/testing/hydrateTestApp.js +2 -2
- package/dist/testing/index.d.ts +2 -1
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +4 -3
- package/dist/testing/loadEnv.d.ts +3 -0
- package/dist/testing/loadEnv.d.ts.map +1 -0
- package/dist/testing/loadEnv.js +28 -0
- package/dist/testing/loadEnvSetup.d.ts +2 -0
- package/dist/testing/loadEnvSetup.d.ts.map +1 -0
- package/dist/testing/loadEnvSetup.js +7 -0
- package/dist/testing/{ensureTestEnvLoaded.d.ts → testEnvIsRequested.d.ts} +1 -2
- package/dist/testing/testEnvIsRequested.d.ts.map +1 -0
- package/dist/testing/testEnvIsRequested.js +7 -0
- package/package.json +1 -1
- package/dist/testing/ensureTestEnvLoaded.d.ts.map +0 -1
- package/dist/testing/ensureTestEnvLoaded.js +0 -32
package/dist/.build-complete
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
1788304961722
|
package/dist/Framework.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export declare class Framework {
|
|
|
14
14
|
devServer?: DevServer;
|
|
15
15
|
prodServer?: ProdServer;
|
|
16
16
|
profiler: TimeProfiler;
|
|
17
|
+
quiet: boolean;
|
|
17
18
|
init(): Promise<FrameworkConfigComplete>;
|
|
18
19
|
build(mode: Mode): Promise<void>;
|
|
19
20
|
clean(mode?: Mode | 'staticSite'): Promise<void>;
|
package/dist/Framework.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Framework.d.ts","sourceRoot":"","sources":["../src/Framework.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAA;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AACjE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAKrC,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAEpD,OAAO,EAA+B,qBAAqB,EAAE,MAAM,mCAAmC,CAAA;AAEtG,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AA8BxD,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAIzE,qBAAa,SAAS;IAClB,MAAM,CAAC,EAAE,uBAAuB,CAAA;IAChC,eAAe,CAAC,EAAE,eAAe,CAAA;IACjC,gBAAgB,CAAC,EAAE,qBAAqB,CAAA;IACxC,mBAAmB,CAAC,EAAE,aAAa,CAAA;IACnC,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,UAAU,CAAC,EAAE,UAAU,CAAA;IAIvB,QAAQ,EAAE,YAAY,CAA4B;
|
|
1
|
+
{"version":3,"file":"Framework.d.ts","sourceRoot":"","sources":["../src/Framework.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAA;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AACjE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAKrC,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAEpD,OAAO,EAA+B,qBAAqB,EAAE,MAAM,mCAAmC,CAAA;AAEtG,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AA8BxD,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAIzE,qBAAa,SAAS;IAClB,MAAM,CAAC,EAAE,uBAAuB,CAAA;IAChC,eAAe,CAAC,EAAE,eAAe,CAAA;IACjC,gBAAgB,CAAC,EAAE,qBAAqB,CAAA;IACxC,mBAAmB,CAAC,EAAE,aAAa,CAAA;IACnC,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,UAAU,CAAC,EAAE,UAAU,CAAA;IAIvB,QAAQ,EAAE,YAAY,CAA4B;IAElD,KAAK,UAAQ;IAEP,IAAI,IAAI,OAAO,CAAC,uBAAuB,CAAC;IAQxC,KAAK,CAAC,IAAI,EAAE,IAAI;IAsBhB,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,GAAG,YAAY;IA0BhC,SAAS;YAID,aAAa;YAab,cAAc;YASd,mBAAmB;YAcnB,MAAM;IAcd,eAAe,IAAI,OAAO,CAAC,SAAS,CAAC;IA2BrC,aAAa,CAAC,MAAM,EAAE,uBAAuB;IAiI7C,gBAAgB,IAAI,OAAO,CAAC,UAAU,CAAC;CA+DhD"}
|
package/dist/Framework.js
CHANGED
|
@@ -47,6 +47,8 @@ export class Framework {
|
|
|
47
47
|
// timeProfiler.ts. Public so those commands can also profile their own top-level phases
|
|
48
48
|
// (createDevServer, devServer.start) with the same instance.
|
|
49
49
|
_defineProperty(this, "profiler", createTimeProfiler(false));
|
|
50
|
+
// tungsten build --quiet: drop progress messages, keep warnings and errors
|
|
51
|
+
_defineProperty(this, "quiet", false);
|
|
50
52
|
}
|
|
51
53
|
async init() {
|
|
52
54
|
// const configOrUndefined = await this.getUserConfig()
|
|
@@ -62,7 +64,8 @@ export class Framework {
|
|
|
62
64
|
const proms = [this.profiler.timeProfileAsync('compile user app', () => this.compileUserApp('dev')), this.profiler.timeProfileAsync('copy framework assets', () => this.copyFrameworkAssets('dev'))];
|
|
63
65
|
await Promise.all(proms);
|
|
64
66
|
//await devBundle()
|
|
65
|
-
|
|
67
|
+
// dev branch: only tungsten build sets quiet, so this check cannot fire yet
|
|
68
|
+
if (!this.quiet) cliNews(`Build complete`);
|
|
66
69
|
} else {
|
|
67
70
|
const proms = [this.profiler.timeProfileAsync('compile user app', () => this.compileUserApp('prod')), this.profiler.timeProfileAsync('copy framework assets', () => this.copyFrameworkAssets('prod'))];
|
|
68
71
|
await Promise.all(proms);
|
|
@@ -125,17 +128,17 @@ export class Framework {
|
|
|
125
128
|
if (this.config === undefined) {
|
|
126
129
|
throw new TungstenError(`SxyFramework.copyFrameworkAssets() error: config is undefined`);
|
|
127
130
|
}
|
|
128
|
-
cliOut(`Getting framework modules`);
|
|
131
|
+
if (!this.quiet) cliOut(`Getting framework modules`);
|
|
129
132
|
this.frameworkModules = getAllTungstenClientModules();
|
|
130
|
-
cliOut(`Getting framework client aliases`);
|
|
133
|
+
if (!this.quiet) cliOut(`Getting framework client aliases`);
|
|
131
134
|
this.clientImportAliases = getTungstenClientPackageAliases();
|
|
132
|
-
cliOut(`Creating app files`);
|
|
135
|
+
if (!this.quiet) cliOut(`Creating app files`);
|
|
133
136
|
await Promise.all([createInstanceConfigFile(this.config, mode), createClientFiles(this.config, mode)]);
|
|
134
137
|
}
|
|
135
138
|
async bundle() {
|
|
136
139
|
const projectDir = process.cwd();
|
|
137
140
|
if (this.config === undefined) throw new TungstenError(`SxyFramework.bundle() error, this.config is undefined`);
|
|
138
|
-
await bundle(projectDir);
|
|
141
|
+
await bundle(projectDir, this.quiet);
|
|
139
142
|
// rollup extracts the framework component css in its own process, so the manifest only
|
|
140
143
|
// exists once bundling has finished
|
|
141
144
|
if (this.compilationInfo !== undefined) {
|
|
@@ -148,7 +151,8 @@ export class Framework {
|
|
|
148
151
|
}
|
|
149
152
|
async createDevServer() {
|
|
150
153
|
return this.profiler.timeProfileAsync('create dev server', async () => {
|
|
151
|
-
|
|
154
|
+
// dev only: only tungsten build sets quiet, so this check cannot fire yet
|
|
155
|
+
if (!this.quiet) cliOut(`Creating dev server`);
|
|
152
156
|
// TS define requires a var to exist or not, so we will initialize it to undefined to satisfy this expectation
|
|
153
157
|
global.tungstenPublicEnv = {};
|
|
154
158
|
// should we default the debug value? we'd have issues if they set DEBUG to undef
|
|
@@ -194,10 +198,11 @@ export class Framework {
|
|
|
194
198
|
...process.env
|
|
195
199
|
};
|
|
196
200
|
//const envsLoadedMessages: string[] = []
|
|
201
|
+
const quiet = this.quiet;
|
|
197
202
|
function loadEnv(fileName, filePath, prefix = '') {
|
|
198
203
|
const env = dotenv.parse(readFileSync(filePath, 'utf-8'));
|
|
199
204
|
someEnvLoaded = true;
|
|
200
|
-
cliOut(`${fileName} loaded from ${filePath}`);
|
|
205
|
+
if (!quiet) cliOut(`${fileName} loaded from ${filePath}`);
|
|
201
206
|
addToEnv(env, process.env, prefix, trueEnv, config.suppressEnvOverwriteWarnings);
|
|
202
207
|
//console.log('process.env after injecting ' + fileName, process.env)
|
|
203
208
|
}
|
|
@@ -224,7 +229,7 @@ export class Framework {
|
|
|
224
229
|
if (publicEnvExists) {
|
|
225
230
|
await loadEnv('.env.public', publicEnvLocation, 'TUNGSTEN_PUBLIC_');
|
|
226
231
|
}
|
|
227
|
-
if (!someEnvLoaded) cliOut('No env files were loaded');
|
|
232
|
+
if (!someEnvLoaded && !this.quiet) cliOut('No env files were loaded');
|
|
228
233
|
// If there are env schemas, load the relevant env and parse with schemas
|
|
229
234
|
if ('privateEnvSchema' in envSchemas) {
|
|
230
235
|
// parse process.env
|
|
@@ -237,7 +242,7 @@ export class Framework {
|
|
|
237
242
|
// is set to alter data
|
|
238
243
|
const withCorePrivateEnv = tungstenCorePrivateEnvSchema.parse(privateEnv);
|
|
239
244
|
global.tungstenPrivateEnv = withCorePrivateEnv;
|
|
240
|
-
cliOut('tungsten private env loaded and passed schema validation'); // save this so that we can show all messages about loading .env files first
|
|
245
|
+
if (!this.quiet) cliOut('tungsten private env loaded and passed schema validation'); // save this so that we can show all messages about loading .env files first
|
|
241
246
|
}
|
|
242
247
|
if ('publicEnvSchema' in envSchemas) {
|
|
243
248
|
// const filteredEnv = objectMap(
|
|
@@ -258,7 +263,7 @@ export class Framework {
|
|
|
258
263
|
writeFileSync(clientWithEnvHandle, publicEnvContent);
|
|
259
264
|
writeFileSync(clientWithEnvHandle, clientContents);
|
|
260
265
|
closeSync(clientWithEnvHandle);
|
|
261
|
-
cliOut('tungsten public env loaded and passed schema validation'); // save this so that we can show all messages about loading .env files first
|
|
266
|
+
if (!this.quiet) cliOut('tungsten public env loaded and passed schema validation'); // save this so that we can show all messages about loading .env files first
|
|
262
267
|
} else {
|
|
263
268
|
//cliOut('copy client to clientWithEnv.js')
|
|
264
269
|
copyFileSync(join(projectDir, bundleFolder, 'client.js'), join(projectDir, bundleFolder, 'clientWithEnv.js'));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/bin/commands/build.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/bin/commands/build.ts"],"names":[],"mappings":"AA2DA,OAAO,EAAE,CAAA"}
|
|
@@ -4,14 +4,17 @@ import { Framework } from "../../Framework.js";
|
|
|
4
4
|
import { cliOut, cliNews, cliWarn } from "../../cliOutput.js";
|
|
5
5
|
import { staticSiteFolder } from "../../settings.js";
|
|
6
6
|
import { createTimeProfiler } from "../../timeProfiler.js";
|
|
7
|
-
const
|
|
7
|
+
const args = process.argv.slice(3);
|
|
8
|
+
const profile = args.includes('--profile');
|
|
9
|
+
const quiet = args.includes('--quiet');
|
|
8
10
|
//// prep the app
|
|
9
11
|
const sxyFramework = new Framework();
|
|
10
12
|
sxyFramework.profiler = createTimeProfiler(profile);
|
|
13
|
+
sxyFramework.quiet = quiet;
|
|
11
14
|
await sxyFramework.init();
|
|
12
|
-
cliOut('Removing old builds');
|
|
15
|
+
if (!quiet) cliOut('Removing old builds');
|
|
13
16
|
await sxyFramework.clean('prod');
|
|
14
|
-
cliOut('Building');
|
|
17
|
+
if (!quiet) cliOut('Building');
|
|
15
18
|
await sxyFramework.build('prod');
|
|
16
19
|
// //// dev
|
|
17
20
|
// import { prodBuildFolder } from '../../settings.js'
|
|
@@ -22,11 +25,11 @@ await sxyFramework.build('prod');
|
|
|
22
25
|
// //// end dev
|
|
23
26
|
if (sxyFramework.config.staticSite) {
|
|
24
27
|
// eslint-disable-line @typescript-eslint/no-non-null-assertion, no-type-assertion/no-type-assertion -- config better be set
|
|
25
|
-
cliOut(`Building static site`);
|
|
28
|
+
if (!quiet) cliOut(`Building static site`);
|
|
26
29
|
await sxyFramework.clean('staticSite');
|
|
27
30
|
await sxyFramework.staticGen();
|
|
28
|
-
cliNews(`Static site generation complete. Your site is in ${staticSiteFolder}.` + ` View it with ${chalk.brightblue('npx tungsten static')}` + ` or add ${chalk.brightblue('"static": "tungsten static"')} to your package.json scripts` + ` and run ${chalk.brightblue('pnpm static')}`);
|
|
29
|
-
} else {
|
|
31
|
+
if (!quiet) cliNews(`Static site generation complete. Your site is in ${staticSiteFolder}.` + ` View it with ${chalk.brightblue('npx tungsten static')}` + ` or add ${chalk.brightblue('"static": "tungsten static"')} to your package.json scripts` + ` and run ${chalk.brightblue('pnpm static')}`);
|
|
32
|
+
} else if (!quiet) {
|
|
30
33
|
cliNews(`Production build complete`);
|
|
31
34
|
}
|
|
32
35
|
// The build no longer holds anything open, so it ends by draining the event loop - hard-exiting
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildHelp.d.ts","sourceRoot":"","sources":["../../../src/bin/commands/buildHelp.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// kept out of build.ts so --help does not pay for resolving the build's import tree
|
|
2
|
+
import { cliOut } from "../../cliOutput.js";
|
|
3
|
+
cliOut(`Usage: tungsten build [--profile] [--quiet]
|
|
4
|
+
|
|
5
|
+
Options:
|
|
6
|
+
--profile report the time taken by each build phase
|
|
7
|
+
--quiet suppress progress output; warnings and errors still print`);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"help.d.ts","sourceRoot":"","sources":["../../../src/bin/commands/help.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { cliOut } from "../../cliOutput.js";
|
|
2
|
+
const command = process.argv[2];
|
|
3
|
+
cliOut(`Usage: tungsten <command> [options]
|
|
4
|
+
|
|
5
|
+
Commands:
|
|
6
|
+
dev Start dev mode [--no-boot] [--profile]
|
|
7
|
+
devmon Dev mode, auto-restarts on framework rebuilds (same options as dev)
|
|
8
|
+
build Production build [--profile] [--quiet]
|
|
9
|
+
start Start production server
|
|
10
|
+
static Preview a static site build
|
|
11
|
+
clean Delete build assets
|
|
12
|
+
compile [targets] Compile targets in isolation; run "tungsten compile --help" for details
|
|
13
|
+
compile-simple-package <sourceFolder> <destFolder>
|
|
14
|
+
|
|
15
|
+
Run "tungsten <command> --help" where supported for command-specific options.`);
|
|
16
|
+
process.exit(command === undefined || command === '' ? 1 : 0);
|
package/dist/bin/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bin/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bin/index.ts"],"names":[],"mappings":"AAuEA,OAAO,EAAE,CAAA"}
|
package/dist/bin/index.js
CHANGED
|
@@ -2,10 +2,16 @@ import { cliOut, cliWarn } from "../cliOutput.js";
|
|
|
2
2
|
// get command line args
|
|
3
3
|
const args = process.argv.slice(2);
|
|
4
4
|
const command = args[0];
|
|
5
|
-
if (command === undefined || command === '') {
|
|
6
|
-
cliWarn(`Please choose a command, e.g. "tungsten dev"`);
|
|
7
|
-
}
|
|
8
5
|
switch (command) {
|
|
6
|
+
case undefined:
|
|
7
|
+
case '':
|
|
8
|
+
case 'help':
|
|
9
|
+
case '--help':
|
|
10
|
+
case '-h':
|
|
11
|
+
{
|
|
12
|
+
await import("./commands/help.js");
|
|
13
|
+
break;
|
|
14
|
+
}
|
|
9
15
|
case 'dev':
|
|
10
16
|
{
|
|
11
17
|
cliOut(`Starting Tungsten dev mode`);
|
|
@@ -23,7 +29,12 @@ switch (command) {
|
|
|
23
29
|
}
|
|
24
30
|
case 'build':
|
|
25
31
|
{
|
|
26
|
-
|
|
32
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
33
|
+
await import("./commands/buildHelp.js");
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
// announce before the import: resolving the build's dependencies is a long silent wait
|
|
37
|
+
if (!args.includes('--quiet')) cliOut(`Starting Tungsten production build`);
|
|
27
38
|
process.env.__TUNGSTEN_ENV = 'production';
|
|
28
39
|
process.env.__TUNGSTEN_DEBUG = 'true';
|
|
29
40
|
await import("./commands/build.js");
|
|
@@ -61,6 +72,7 @@ switch (command) {
|
|
|
61
72
|
}
|
|
62
73
|
default:
|
|
63
74
|
{
|
|
64
|
-
cliWarn(`tungsten: unknown command "${command}"`);
|
|
75
|
+
cliWarn(`tungsten: unknown command "${command}" (run "tungsten --help" for usage)`);
|
|
76
|
+
process.exit(1);
|
|
65
77
|
}
|
|
66
78
|
}
|
package/dist/build/bundle.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function bundle(projectDir: string): Promise<unknown>;
|
|
1
|
+
export declare function bundle(projectDir: string, quiet?: boolean): Promise<unknown>;
|
|
2
2
|
//# sourceMappingURL=bundle.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../../src/build/bundle.ts"],"names":[],"mappings":"AAUA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../../src/build/bundle.ts"],"names":[],"mappings":"AAUA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,UAAQ,oBAyC7D"}
|
package/dist/build/bundle.js
CHANGED
|
@@ -5,9 +5,9 @@ import { spawnShellCommand } from "../spawnShellCommand.js";
|
|
|
5
5
|
import { prodBuildFolder, bundleFolder, frameworkDistFolder, clientFolder } from "../settings.js";
|
|
6
6
|
import { errorOut } from "../output.js";
|
|
7
7
|
import { cliLog, cliOut } from "../cliOutput.js";
|
|
8
|
-
export async function bundle(projectDir /*, appConfig: FrameworkConfigComplete*/) {
|
|
8
|
+
export async function bundle(projectDir, quiet = false /*, appConfig: FrameworkConfigComplete*/) {
|
|
9
9
|
return new Promise((resolve, reject) => {
|
|
10
|
-
cliOut('Bundling application');
|
|
10
|
+
if (!quiet) cliOut('Bundling application');
|
|
11
11
|
const frameworkDir = findProjectDir(import.meta.url);
|
|
12
12
|
// if (appConfig.useRootComponent) {
|
|
13
13
|
// let rootComponent = appConfig.rootComponent as string
|
|
@@ -17,11 +17,13 @@ export async function bundle(projectDir /*, appConfig: FrameworkConfigComplete*/
|
|
|
17
17
|
//'node-fetch'
|
|
18
18
|
];
|
|
19
19
|
const command = `cd ${frameworkDir} && npx rollup` + ` --input "${join(projectDir, prodBuildFolder, clientFolder, 'client.js')}"` + ` --file "${join(projectDir, bundleFolder, 'client.js')}"` + ` --config "${join(frameworkDir, frameworkDistFolder, 'build/rollup.user.prod.config.js')}"` + (externalModules.length > 0 ? ` --external ${externalModules.join(',')}` : ``) + ` --inlineDynamicImports --format iife`;
|
|
20
|
-
cliLog('bundle command:', command);
|
|
20
|
+
if (!quiet) cliLog('bundle command:', command);
|
|
21
21
|
const subProcess = spawnShellCommand(command, {
|
|
22
22
|
cwd: frameworkDir /*cwd: projectDir*/ /*, stdio: 'inherit'*/
|
|
23
23
|
});
|
|
24
|
-
subProcess.on('data', data =>
|
|
24
|
+
subProcess.on('data', data => {
|
|
25
|
+
if (!quiet) cliLog(data);
|
|
26
|
+
});
|
|
25
27
|
subProcess.on('close', (code, message) => {
|
|
26
28
|
if (code === 0) resolve(null);else {
|
|
27
29
|
// can we show teh error message? Only getting err code now I think
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
@import "i/T-components-library-
|
|
2
|
-
@import "i/T-components-library-
|
|
1
|
+
@import "i/T-components-library-__StatefulMessage-StatefulMessage.css";
|
|
2
|
+
@import "i/T-components-library-RichTextEditor-RichTextEditor.css";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FrameworkConfigComplete } from '../FrameworkConfig.js';
|
|
2
2
|
import type { CompilationInfo } from '../build/CompilationInfo.js';
|
|
3
3
|
import { AppRoutes } from 'tungsten/routing/AppRoutes.js';
|
|
4
|
-
export declare function getAppRoutes(compilationInfo: CompilationInfo, config: FrameworkConfigComplete): Promise<AppRoutes>;
|
|
4
|
+
export declare function getAppRoutes(compilationInfo: CompilationInfo, config: FrameworkConfigComplete, quiet?: boolean): Promise<AppRoutes>;
|
|
5
5
|
//# sourceMappingURL=getAppRoutes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getAppRoutes.d.ts","sourceRoot":"","sources":["../../src/staticGen/getAppRoutes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AAE/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAGlE,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAA;
|
|
1
|
+
{"version":3,"file":"getAppRoutes.d.ts","sourceRoot":"","sources":["../../src/staticGen/getAppRoutes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AAE/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAGlE,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAA;AAOzD,wBAAsB,YAAY,CAC9B,eAAe,EAAE,eAAe,EAAE,MAAM,EAAE,uBAAuB,EAAE,KAAK,UAAQ,GACjF,OAAO,CAAC,SAAS,CAAC,CAiCpB"}
|
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
import { join } from 'path';
|
|
2
2
|
import { fixExtension } from "../fixExtension.js";
|
|
3
3
|
import { TungstenError } from "../TungstenError.js";
|
|
4
|
+
import { cliLog } from "../cliOutput.js";
|
|
4
5
|
// prod: const appRoutes: AppRoutes = await getRoutes(this.compilationInfo, this.config)
|
|
5
6
|
// this file is outdated and may not work correctly
|
|
6
7
|
// should compare this to the functions used by Servers
|
|
7
|
-
export async function getAppRoutes(compilationInfo, config) {
|
|
8
|
+
export async function getAppRoutes(compilationInfo, config, quiet = false) {
|
|
8
9
|
//const fullBuildLocation = 'file://' + compilationInfo.location
|
|
9
10
|
const routesLocation = config.routesLocation;
|
|
10
11
|
//if (routesLocation === null) return routesLocation // hopefully we are validating
|
|
11
12
|
try {
|
|
12
13
|
if (Array.isArray(routesLocation)) {
|
|
13
14
|
const routesFile = fixExtension(join(compilationInfo.buildCodeLocation, routesLocation[0]));
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
if (!quiet) {
|
|
16
|
+
cliLog('[1] fullBuildLocation', compilationInfo.location);
|
|
17
|
+
cliLog('[1] routesLocation[0]', routesLocation[0]);
|
|
18
|
+
cliLog('joined', join(compilationInfo.location, routesLocation[0]));
|
|
19
|
+
cliLog('[1] routesFile', routesFile);
|
|
20
|
+
}
|
|
18
21
|
const target = 'file://' + routesFile;
|
|
19
|
-
|
|
22
|
+
if (!quiet) cliLog('[1] target', target);
|
|
20
23
|
return (await import(target))[routesLocation[1]];
|
|
21
24
|
} else {
|
|
22
25
|
const target = 'file://' + join(compilationInfo.buildCodeLocation, routesLocation);
|
|
23
|
-
|
|
26
|
+
if (!quiet) cliLog('[2] location', target);
|
|
24
27
|
const module = await import(target);
|
|
25
28
|
if ('routes' in module) return module.routes;else if ('default' in module) return module.default;else throw new TungstenError(`Err, no 'routes' or 'default' export found in routes file ${routesLocation}`);
|
|
26
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"staticGen.d.ts","sourceRoot":"","sources":["../../src/staticGen/staticGen.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAiBhD,wBAAsB,SAAS,CAAC,SAAS,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"staticGen.d.ts","sourceRoot":"","sources":["../../src/staticGen/staticGen.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAiBhD,wBAAsB,SAAS,CAAC,SAAS,EAAE,SAAS,iBA+MnD"}
|
|
@@ -4,7 +4,7 @@ import fsExtra from 'fs-extra';
|
|
|
4
4
|
//import type { SxyFrameworkConfigComplete } from '../FrameworkConfig.js'
|
|
5
5
|
import { staticSiteFolder, staticFolder, assetsFolder, publicFolder, bundleFolder, componentCssFolder, frameworkCssFolder } from "../settings.js";
|
|
6
6
|
import { getAppRoutes } from "./getAppRoutes.js";
|
|
7
|
-
import { cliError, cliWarn } from "../cliOutput.js";
|
|
7
|
+
import { cliError, cliLog, cliWarn } from "../cliOutput.js";
|
|
8
8
|
import { matchPath } from "../routing/matchPath.js";
|
|
9
9
|
import { throwError } from "../throwError.js";
|
|
10
10
|
import { RouteKeyIsPath, StringIsPath } from "../routing/RouteTypes.js";
|
|
@@ -18,11 +18,12 @@ export async function staticGen(framework) {
|
|
|
18
18
|
if (config === undefined) {
|
|
19
19
|
throwError('staticGen()', `expected framework.config to be set: ${framework.config}`);
|
|
20
20
|
}
|
|
21
|
+
const quiet = framework.quiet;
|
|
21
22
|
const siteBasePath = config.siteBasePath;
|
|
22
|
-
|
|
23
|
+
if (!quiet) cliLog('siteBasePath', siteBasePath);
|
|
23
24
|
const projectDir = process.cwd();
|
|
24
25
|
//let appRoutes: RouteDefinition[] | Record<RouteKey, RouteDefinition> = await getAppRoutes(framework.compilationInfo, config)
|
|
25
|
-
const getRoutes = await getAppRoutes(framework.compilationInfo, config);
|
|
26
|
+
const getRoutes = await getAppRoutes(framework.compilationInfo, config, quiet);
|
|
26
27
|
// ! unsure about this
|
|
27
28
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
28
29
|
const appRoutes = getRoutes === null ? {
|
|
@@ -89,7 +90,7 @@ export async function staticGen(framework) {
|
|
|
89
90
|
const url = serverLocation + path;
|
|
90
91
|
let links;
|
|
91
92
|
try {
|
|
92
|
-
|
|
93
|
+
if (!quiet) cliLog('get URL', url);
|
|
93
94
|
const response = await fetch(url);
|
|
94
95
|
// fetch, unlike axios, resolves on non-2xx - so check explicitly, or we'd
|
|
95
96
|
// write error pages out as static HTML
|
|
@@ -145,7 +146,7 @@ export async function staticGen(framework) {
|
|
|
145
146
|
for (const [path, route] of Object.entries(finalRoutes)) {
|
|
146
147
|
await renderPath(path, siteBasePath);
|
|
147
148
|
}
|
|
148
|
-
|
|
149
|
+
if (!quiet) cliLog('rewriteMap', rewriteMap);
|
|
149
150
|
const copyPromises = [fsExtra.copy(join(buildLocation, staticFolder), join(projectDir, staticSiteFolder)),
|
|
150
151
|
// assets folder
|
|
151
152
|
existsSync(join(buildLocation, assetsFolder)) ? fsExtra.copy(join(buildLocation, assetsFolder), join(projectDir, staticSiteFolder, 'assets')) : null,
|
|
@@ -15,7 +15,7 @@ import { initStores } from "../Servers/initStores.js";
|
|
|
15
15
|
import { deleteNodeIfRendered } from "../update/integrateUpdateVdom.js";
|
|
16
16
|
import { UpdateScheduler } from "../update/UpdateScheduler.js";
|
|
17
17
|
import { DomPointer } from "../DomPointer.js";
|
|
18
|
-
import {
|
|
18
|
+
import { waitForEnvIfLoading } from "./loadEnv.js";
|
|
19
19
|
// hydrate.tsx references several DOM globals directly (Node.COMMENT_NODE, `instanceof Text`, the
|
|
20
20
|
// bare `document`) the way real browser code always can - happy-dom only puts these on its own
|
|
21
21
|
// Window, not on Node.js's global scope. Every hand-written hydration test before this harness
|
|
@@ -108,7 +108,7 @@ class HydrateTestAppImplementation {
|
|
|
108
108
|
* client hydrator does, so a caller reproducing that class of bug should assert on the rejection.
|
|
109
109
|
*/
|
|
110
110
|
export async function hydrateTestApp(RootComponent, ...args) {
|
|
111
|
-
await
|
|
111
|
+
await waitForEnvIfLoading();
|
|
112
112
|
const options = args[0]; // eslint-disable-line no-type-assertion/no-type-assertion
|
|
113
113
|
const suppliedDocument = options?.document ?? globalThis.document; // eslint-disable-line no-type-assertion/no-type-assertion
|
|
114
114
|
if (suppliedDocument === undefined) {
|
package/dist/testing/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ConstructPackage, TungstenBaseComponent, TungstenBaseComponentType, TungstenComponentPropsBase } from '../Components.jsx';
|
|
2
|
-
export {
|
|
2
|
+
export { loadEnv } from './loadEnv.js';
|
|
3
|
+
export { testEnvVariableName } from './testEnvIsRequested.js';
|
|
3
4
|
export { hydrateTestApp, type HydrateTestApp, type HydrateTestAppOptions } from './hydrateTestApp.js';
|
|
4
5
|
import type { TrueStore } from '../Store/makeStore.js';
|
|
5
6
|
export type ComponentProps<ComponentType extends TungstenBaseComponentType<any, any>> = InstanceType<ComponentType>['props'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,gBAAgB,EAChB,qBAAqB,EACrB,yBAAyB,EACzB,0BAA0B,EAC7B,MAAM,mBAAmB,CAAA;AAM1B,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"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"}
|
package/dist/testing/index.js
CHANGED
|
@@ -8,8 +8,9 @@ function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a),
|
|
|
8
8
|
function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
9
9
|
import { Instance } from "../Instance/Instance.js";
|
|
10
10
|
import { initStores } from "../Servers/initStores.js";
|
|
11
|
-
import {
|
|
12
|
-
export {
|
|
11
|
+
import { waitForEnvIfLoading } from "./loadEnv.js";
|
|
12
|
+
export { loadEnv } from "./loadEnv.js";
|
|
13
|
+
export { testEnvVariableName } from "./testEnvIsRequested.js";
|
|
13
14
|
export { hydrateTestApp } from "./hydrateTestApp.js";
|
|
14
15
|
import { createTungstenRootComponent, deleteTungstenRoot } from "../update/integrateUpdateVdom.js";
|
|
15
16
|
import { UpdateScheduler } from "../update/UpdateScheduler.js";
|
|
@@ -87,7 +88,7 @@ export async function createTestApp(
|
|
|
87
88
|
// type arguments - so a generic component's own parameters collapse to
|
|
88
89
|
// their constraints before `props` is ever considered.
|
|
89
90
|
RootComponent, ...args) {
|
|
90
|
-
await
|
|
91
|
+
await waitForEnvIfLoading();
|
|
91
92
|
const options = args[0];
|
|
92
93
|
const suppliedDocument = options?.document ?? globalThis.document;
|
|
93
94
|
if (suppliedDocument === undefined) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadEnv.d.ts","sourceRoot":"","sources":["../../src/testing/loadEnv.ts"],"names":[],"mappings":"AAaA,wBAAgB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAWvC;AAID,wBAAgB,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,CAEnD"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { getUserConfig } from "../getUserConfig.js";
|
|
2
|
+
import { loadEnvsDev } from "../Servers/loadEnvsDev.js";
|
|
3
|
+
import { testEnvIsRequested, testEnvVariableName } from "./testEnvIsRequested.js";
|
|
4
|
+
let loadPromise;
|
|
5
|
+
// Populate global.tungstenPublicEnv / global.tungstenPrivateEnv for DOM component tests, once
|
|
6
|
+
// per process. Compiled client component code reads these as bare globals, so they must exist
|
|
7
|
+
// before any component runs under the test runner. Call this from the test runner setup hook.
|
|
8
|
+
//
|
|
9
|
+
// TUNGSTEN_TEST_ENV chooses which env files: set it to prefer .env.test* over the base files.
|
|
10
|
+
// A missing or invalid env schemas file is a hard error - an app that asked for env and did not
|
|
11
|
+
// get it must not run its tests regardless.
|
|
12
|
+
export function loadEnv() {
|
|
13
|
+
if (loadPromise === undefined) {
|
|
14
|
+
loadPromise = (async () => {
|
|
15
|
+
const config = await getUserConfig({}, 'silent');
|
|
16
|
+
const useTestEnvFiles = testEnvIsRequested(process.env[testEnvVariableName]);
|
|
17
|
+
// iteration 0: schemas are stable within a test run.
|
|
18
|
+
// _firstLoad = false: suppress the CLI boot output.
|
|
19
|
+
await loadEnvsDev(config, 0, process.env, false, useTestEnvFiles);
|
|
20
|
+
})();
|
|
21
|
+
}
|
|
22
|
+
return loadPromise;
|
|
23
|
+
}
|
|
24
|
+
// Passive companion for the test harness: wait for an in-progress loadEnv(), or do nothing if
|
|
25
|
+
// setup never started one. Never initiates a load, so it never fails on its own.
|
|
26
|
+
export function waitForEnvIfLoading() {
|
|
27
|
+
return loadPromise ?? Promise.resolve();
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadEnvSetup.d.ts","sourceRoot":"","sources":["../../src/testing/loadEnvSetup.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Side-effect setup module for the sxy-test-runner `setup` file-location form, which imports the
|
|
2
|
+
// file rather than calling an export. Reference it from an app's test config to load app env for
|
|
3
|
+
// component tests:
|
|
4
|
+
// setup: ['node_modules/tungsten/dist/testing/loadEnvSetup.js']
|
|
5
|
+
// (the path is resolved from the project dir). Or call loadEnv() directly in a setup function.
|
|
6
|
+
import { loadEnv } from "./loadEnv.js";
|
|
7
|
+
await loadEnv();
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export declare const testEnvVariableName = "TUNGSTEN_TEST_ENV";
|
|
2
2
|
export declare function testEnvIsRequested(value: string | undefined): boolean;
|
|
3
|
-
|
|
4
|
-
//# sourceMappingURL=ensureTestEnvLoaded.d.ts.map
|
|
3
|
+
//# sourceMappingURL=testEnvIsRequested.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testEnvIsRequested.d.ts","sourceRoot":"","sources":["../../src/testing/testEnvIsRequested.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,mBAAmB,sBAAsB,CAAA;AAEtD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAIrE"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Set this to prefer the .env.test* files over the base ones when test env is loaded.
|
|
2
|
+
export const testEnvVariableName = 'TUNGSTEN_TEST_ENV';
|
|
3
|
+
export function testEnvIsRequested(value) {
|
|
4
|
+
if (value === undefined) return false;
|
|
5
|
+
const normalized = value.trim().toLowerCase();
|
|
6
|
+
return normalized !== '' && normalized !== '0' && normalized !== 'false';
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ensureTestEnvLoaded.d.ts","sourceRoot":"","sources":["../../src/testing/ensureTestEnvLoaded.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,mBAAmB,sBAAsB,CAAA;AAEtD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAIrE;AAaD,wBAAgB,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,CAYnD"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { getUserConfig } from "../getUserConfig.js";
|
|
2
|
-
import { loadEnvsDev } from "../Servers/loadEnvsDev.js";
|
|
3
|
-
// Set this in the test script or a runner hook to have component tests load app env.
|
|
4
|
-
export const testEnvVariableName = 'TUNGSTEN_TEST_ENV';
|
|
5
|
-
export function testEnvIsRequested(value) {
|
|
6
|
-
if (value === undefined) return false;
|
|
7
|
-
const normalized = value.trim().toLowerCase();
|
|
8
|
-
return normalized !== '' && normalized !== '0' && normalized !== 'false';
|
|
9
|
-
}
|
|
10
|
-
let loadPromise;
|
|
11
|
-
// Populate global.tungstenPublicEnv / global.tungstenPrivateEnv for DOM component tests,
|
|
12
|
-
// exactly once per process. Compiled client component code reads these as bare globals, so
|
|
13
|
-
// they must exist before any component runs under the test runner.
|
|
14
|
-
//
|
|
15
|
-
// Opt-in, via TUNGSTEN_TEST_ENV. An app that sets it gets its envs loaded with the .env.test*
|
|
16
|
-
// files preferred over the base ones, and a missing or invalid env schemas file is then a hard
|
|
17
|
-
// error — an app that asked for env and did not get it must not run its tests regardless.
|
|
18
|
-
// Without the variable nothing is loaded, which is what a package with no env schemas of its
|
|
19
|
-
// own (the framework itself, or a component library) needs.
|
|
20
|
-
export function ensureTestEnvLoaded() {
|
|
21
|
-
if (loadPromise === undefined) {
|
|
22
|
-
loadPromise = (async () => {
|
|
23
|
-
if (!testEnvIsRequested(process.env[testEnvVariableName])) return;
|
|
24
|
-
const config = await getUserConfig({}, 'silent');
|
|
25
|
-
// iteration 0: schemas are stable within a test run.
|
|
26
|
-
// _firstLoad = false: suppress the CLI boot output.
|
|
27
|
-
// useTestEnvFiles = true: prefer .env.test* files.
|
|
28
|
-
await loadEnvsDev(config, 0, process.env, false, true);
|
|
29
|
-
})();
|
|
30
|
-
}
|
|
31
|
-
return loadPromise;
|
|
32
|
-
}
|