@rindo/core 2.17.1 → 2.17.2

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.
Files changed (40) hide show
  1. package/cli/config-flags.d.ts +12 -4
  2. package/cli/index.cjs +113 -73
  3. package/cli/index.d.ts +1 -1
  4. package/cli/index.js +113 -73
  5. package/cli/package.json +1 -1
  6. package/compiler/package.json +1 -1
  7. package/compiler/rindo.js +348 -61
  8. package/compiler/rindo.min.js +2 -2
  9. package/dependencies.json +1 -1
  10. package/dev-server/client/index.js +1 -1
  11. package/dev-server/client/package.json +1 -1
  12. package/dev-server/connector.html +2 -2
  13. package/dev-server/index.js +1 -1
  14. package/dev-server/package.json +1 -1
  15. package/dev-server/server-process.js +2 -2
  16. package/internal/app-data/package.json +1 -1
  17. package/internal/client/css-shim.js +1 -1
  18. package/internal/client/dom.js +1 -1
  19. package/internal/client/index.js +1 -1
  20. package/internal/client/package.json +1 -1
  21. package/internal/client/patch-browser.js +1 -1
  22. package/internal/client/patch-esm.js +1 -1
  23. package/internal/client/shadow-css.js +1 -1
  24. package/internal/hydrate/package.json +1 -1
  25. package/internal/package.json +1 -1
  26. package/internal/rindo-private.d.ts +12 -2
  27. package/internal/rindo-public-compiler.d.ts +1 -1
  28. package/internal/testing/package.json +1 -1
  29. package/mock-doc/index.cjs +41 -3
  30. package/mock-doc/index.d.ts +15 -0
  31. package/mock-doc/index.js +41 -3
  32. package/mock-doc/package.json +1 -1
  33. package/package.json +1 -1
  34. package/screenshot/package.json +1 -1
  35. package/sys/node/index.js +1 -1
  36. package/sys/node/package.json +1 -1
  37. package/sys/node/worker.js +1 -1
  38. package/testing/index.js +37 -22
  39. package/testing/mocks.d.ts +7 -6
  40. package/testing/package.json +1 -1
@@ -94,9 +94,17 @@ declare type LogLevelFlags = ObjectFromKeys<typeof LOG_LEVEL_CLI_ARGS, LogLevel>
94
94
  * on actual flags passed by the user.
95
95
  */
96
96
  export interface ConfigFlags extends BooleanConfigFlags, StringConfigFlags, NumberConfigFlags, StringNumberConfigFlags, LogLevelFlags {
97
- task?: TaskCommand | null;
98
- args?: string[];
99
- knownArgs?: string[];
100
- unknownArgs?: string[];
97
+ task: TaskCommand | null;
98
+ args: string[];
99
+ knownArgs: string[];
100
+ unknownArgs: string[];
101
101
  }
102
+ /**
103
+ * Helper function for initializing a `ConfigFlags` object. Provide any overrides
104
+ * for default values and off you go!
105
+ *
106
+ * @param init an object with any overrides for default values
107
+ * @returns a complete CLI flag object
108
+ */
109
+ export declare const createConfigFlags: (init?: Partial<ConfigFlags>) => ConfigFlags;
102
110
  export {};
package/cli/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Rindo CLI (CommonJS) v2.17.1 | MIT Licensed | https://rindojs.web.app
2
+ Rindo CLI (CommonJS) v2.17.2 | MIT Licensed | https://rindojs.web.app
3
3
  */
4
4
  'use strict';
5
5
 
@@ -521,46 +521,54 @@ const CLI_ARG_ALIASES = {
521
521
  help: 'h',
522
522
  port: 'p',
523
523
  version: 'v',
524
- };
525
-
524
+ };
526
525
  /**
527
- * Parse command line arguments into a structured `ConfigFlags` object
526
+ * Helper function for initializing a `ConfigFlags` object. Provide any overrides
527
+ * for default values and off you go!
528
528
  *
529
- * @param args an array of config flags
530
- * @param sys an optional compiler system
531
- * @returns a structured ConfigFlags object
529
+ * @param init an object with any overrides for default values
530
+ * @returns a complete CLI flag object
532
531
  */
533
- const parseFlags = (args, sys) => {
532
+ const createConfigFlags = (init = {}) => {
534
533
  const flags = {
535
534
  task: null,
536
535
  args: [],
537
536
  knownArgs: [],
538
537
  unknownArgs: [],
538
+ ...init,
539
539
  };
540
+ return flags;
541
+ };
542
+
543
+ /**
544
+ * Parse command line arguments into a structured `ConfigFlags` object
545
+ *
546
+ * @param args an array of CLI flags
547
+ * @param _sys an optional compiler system
548
+ * @returns a structured ConfigFlags object
549
+ */
550
+ const parseFlags = (args, _sys) => {
551
+ // TODO: remove the _sys parameter here ^^ (for v3)
552
+ const flags = createConfigFlags();
540
553
  // cmd line has more priority over npm scripts cmd
541
554
  flags.args = Array.isArray(args) ? args.slice() : [];
542
555
  if (flags.args.length > 0 && flags.args[0] && !flags.args[0].startsWith('-')) {
543
556
  flags.task = flags.args[0];
544
557
  }
545
558
  parseArgs(flags, flags.args);
546
- if (sys && sys.name === 'node') {
547
- const envArgs = getNpmConfigEnvArgs(sys);
548
- parseArgs(flags, envArgs);
549
- envArgs.forEach((envArg) => {
550
- if (!flags.args.includes(envArg)) {
551
- flags.args.push(envArg);
552
- }
553
- });
554
- }
555
559
  if (flags.task != null) {
556
560
  const i = flags.args.indexOf(flags.task);
557
561
  if (i > -1) {
558
562
  flags.args.splice(i, 1);
559
563
  }
560
564
  }
561
- flags.unknownArgs = flags.args.filter((arg) => {
562
- return !flags.knownArgs.includes(arg);
563
- });
565
+ // to find unknown / unrecognized arguments we filter `args`, including only
566
+ // arguments whose normalized form is not found in `knownArgs`. `knownArgs`
567
+ // is populated during the call to `parseArgs` above. For arguments like
568
+ // `--foobar` the string `"--foobar"` will be added, while for more
569
+ // complicated arguments like `--bizBoz=bop` or `--bizBoz bop` just the
570
+ // string `"--bizBoz"` will be added.
571
+ flags.unknownArgs = flags.args.filter((arg) => !flags.knownArgs.includes(parseEqualsArg(arg)[0]));
564
572
  return flags;
565
573
  };
566
574
  /**
@@ -746,17 +754,17 @@ const getValue = (args, configCaseName) => {
746
754
  let matchingArg;
747
755
  args.forEach((arg, i) => {
748
756
  if (arg.startsWith(`--${dashCaseName}=`) || arg.startsWith(`--${configCaseName}=`)) {
749
- value = getEqualsValue(arg);
750
- matchingArg = arg;
757
+ // our argument was passed at the command-line in the format --argName=arg-value
758
+ [matchingArg, value] = parseEqualsArg(arg);
751
759
  }
752
760
  else if (arg === `--${dashCaseName}` || arg === `--${configCaseName}`) {
761
+ // the next value in the array is assumed to be a value for this argument
753
762
  value = args[i + 1];
754
763
  matchingArg = arg;
755
764
  }
756
765
  else if (alias) {
757
766
  if (arg.startsWith(`-${alias}=`)) {
758
- value = getEqualsValue(arg);
759
- matchingArg = arg;
767
+ [matchingArg, value] = parseEqualsArg(arg);
760
768
  }
761
769
  else if (arg === `-${alias}`) {
762
770
  value = args[i + 1];
@@ -767,13 +775,42 @@ const getValue = (args, configCaseName) => {
767
775
  return { value, matchingArg };
768
776
  };
769
777
  /**
770
- * When a parameter is set in the format `--foobar=12` at the CLI (as opposed to
771
- * `--foobar 12`) we want to get the value after the `=` sign
778
+ * Parse an 'equals' argument, which is a CLI argument-value pair in the
779
+ * format `--foobar=12` (as opposed to a space-separated format like
780
+ * `--foobar 12`).
781
+ *
782
+ * To parse this we split on the `=`, returning the first part as the argument
783
+ * name and the second part as the value. We join the value on `"="` in case
784
+ * there is another `"="` in the argument.
785
+ *
786
+ * This function is safe to call with any arg, and can therefore be used as
787
+ * an argument 'normalizer'. If CLI argument is not an 'equals' argument then
788
+ * the return value will be a tuple of the original argument and an empty
789
+ * string `""` for the value.
790
+ *
791
+ * In code terms, if you do:
792
+ *
793
+ * ```ts
794
+ * const [arg, value] = parseEqualsArg("--myArgument")
795
+ * ```
796
+ *
797
+ * Then `arg` will be `"--myArgument"` and `value` will be `""`, whereas if
798
+ * you do:
799
+ *
772
800
  *
773
- * @param commandArgument the arg in question
774
- * @returns the value after the `=`
801
+ * ```ts
802
+ * const [arg, value] = parseEqualsArg("--myArgument=myValue")
803
+ * ```
804
+ *
805
+ * Then `arg` will be `"--myArgument"` and `value` will be `"myValue"`.
806
+ *
807
+ * @param arg the arg in question
808
+ * @returns a tuple containing the arg name and the value (if present)
775
809
  */
776
- const getEqualsValue = (commandArgument) => commandArgument.split('=').slice(1).join('=');
810
+ const parseEqualsArg = (arg) => {
811
+ const [originalArg, ...value] = arg.split('=');
812
+ return [originalArg, value.join('=')];
813
+ };
777
814
  /**
778
815
  * Small helper for getting type-system-level assurance that a `string` can be
779
816
  * narrowed to a `LogLevel`
@@ -787,28 +824,12 @@ const isLogLevel = (maybeLogLevel) =>
787
824
  // `ReadonlyArray` 😢 thus we `as any`
788
825
  //
789
826
  // see microsoft/TypeScript#31018 for some discussion of this
790
- LOG_LEVELS.includes(maybeLogLevel);
791
- const getNpmConfigEnvArgs = (sys) => {
792
- // process.env.npm_config_argv
793
- // {"remain":["4444"],"cooked":["run","serve","--port","4444"],"original":["run","serve","--port","4444"]}
794
- let args = [];
795
- try {
796
- const npmConfigArgs = sys.getEnvironmentVar('npm_config_argv');
797
- if (npmConfigArgs) {
798
- args = JSON.parse(npmConfigArgs).original;
799
- if (args[0] === 'run') {
800
- args = args.slice(2);
801
- }
802
- }
803
- }
804
- catch (e) { }
805
- return args;
806
- };
827
+ LOG_LEVELS.includes(maybeLogLevel);
807
828
 
808
829
  const dependencies = [
809
830
  {
810
831
  name: "@rindo/core",
811
- version: "2.17.1",
832
+ version: "2.17.2",
812
833
  main: "compiler/rindo.js",
813
834
  resources: [
814
835
  "package.json",
@@ -1142,6 +1163,7 @@ const isInteractive = (sys, flags, object) => {
1142
1163
  return terminalInfo.tty && !terminalInfo.ci;
1143
1164
  };
1144
1165
  const UUID_REGEX = new RegExp(/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i);
1166
+ // Plucked from https://github.com/navify/jigra/blob/HEAD/cli/src/util/uuid.ts
1145
1167
  function uuidv4() {
1146
1168
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
1147
1169
  const r = (Math.random() * 16) | 0;
@@ -1303,6 +1325,15 @@ async function telemetryAction(sys, config, coreCompiler, action) {
1303
1325
  throw error;
1304
1326
  }
1305
1327
  }
1328
+ /**
1329
+ * Helper function to determine if a Rindo configuration builds an application.
1330
+ *
1331
+ * This function is a rough approximation whether an application is generated as a part of a Rindo build, based on
1332
+ * contents of the project's `rindo.config.ts` file.
1333
+ *
1334
+ * @param config the configuration used by the Rindo project
1335
+ * @returns true if we believe the project generates an application, false otherwise
1336
+ */
1306
1337
  function hasAppTarget(config) {
1307
1338
  return config.outputTargets.some((target) => target.type === WWW && (!!target.serviceWorker || (!!target.baseUrl && target.baseUrl !== '/')));
1308
1339
  }
@@ -1310,7 +1341,15 @@ function isUsingYarn(sys) {
1310
1341
  var _a;
1311
1342
  return ((_a = sys.getEnvironmentVar('npm_execpath')) === null || _a === void 0 ? void 0 : _a.includes('yarn')) || false;
1312
1343
  }
1313
- async function getActiveTargets(config) {
1344
+ /**
1345
+ * Build a list of the different types of output targets used in a Rindo configuration.
1346
+ *
1347
+ * Duplicate entries will not be returned from the list
1348
+ *
1349
+ * @param config the configuration used by the Rindo project
1350
+ * @returns a unique list of output target types found in the Rindo configuration
1351
+ */
1352
+ function getActiveTargets(config) {
1314
1353
  const result = config.outputTargets.map((t) => t.type);
1315
1354
  return Array.from(new Set(result));
1316
1355
  }
@@ -1327,7 +1366,7 @@ async function getActiveTargets(config) {
1327
1366
  const prepareData = async (coreCompiler, config, sys, duration_ms, component_count = undefined) => {
1328
1367
  const { typescript, rollup } = coreCompiler.versions || { typescript: 'unknown', rollup: 'unknown' };
1329
1368
  const { packages, packagesNoVersions } = await getInstalledPackages(sys, config);
1330
- const targets = await getActiveTargets(config);
1369
+ const targets = getActiveTargets(config);
1331
1370
  const yarn = isUsingYarn(sys);
1332
1371
  const rindo = coreCompiler.version || 'unknown';
1333
1372
  const system = `${sys.name} ${sys.version}`;
@@ -1390,14 +1429,13 @@ const CONFIG_PROPS_TO_DELETE = ['sys', 'logger', 'tsCompilerOptions', 'devServer
1390
1429
  * @returns an anonymized copy of the same config
1391
1430
  */
1392
1431
  const anonymizeConfigForTelemetry = (config) => {
1393
- var _a;
1394
1432
  const anonymizedConfig = { ...config };
1395
1433
  for (const prop of CONFIG_PROPS_TO_ANONYMIZE) {
1396
1434
  if (anonymizedConfig[prop] !== undefined) {
1397
1435
  anonymizedConfig[prop] = 'omitted';
1398
1436
  }
1399
1437
  }
1400
- anonymizedConfig.outputTargets = ((_a = config.outputTargets) !== null && _a !== void 0 ? _a : []).map((target) => {
1438
+ anonymizedConfig.outputTargets = config.outputTargets.map((target) => {
1401
1439
  // Anonymize the outputTargets on our configuration, taking advantage of the
1402
1440
  // optional 2nd argument to `JSON.stringify`. If anything is not a string
1403
1441
  // we retain it so that any nested properties are handled, else we check
@@ -1618,7 +1656,7 @@ function getMajorVersion(version) {
1618
1656
  return parts[0];
1619
1657
  }
1620
1658
 
1621
- const taskBuild = async (coreCompiler, config, sys) => {
1659
+ const taskBuild = async (coreCompiler, config) => {
1622
1660
  if (config.flags.watch) {
1623
1661
  // watch build
1624
1662
  await taskWatch(coreCompiler, config);
@@ -1631,10 +1669,7 @@ const taskBuild = async (coreCompiler, config, sys) => {
1631
1669
  const versionChecker = startCheckVersion(config, coreCompiler.version);
1632
1670
  const compiler = await coreCompiler.createCompiler(config);
1633
1671
  const results = await compiler.build();
1634
- // TODO: make this parameter no longer optional, remove the surrounding if statement
1635
- if (sys) {
1636
- await telemetryBuildFinishedAction(sys, config, coreCompiler, results);
1637
- }
1672
+ await telemetryBuildFinishedAction(config.sys, config, coreCompiler, results);
1638
1673
  await compiler.destroy();
1639
1674
  if (results.hasError) {
1640
1675
  exitCode = 1;
@@ -1998,10 +2033,7 @@ const taskHelp = async (flags, logger, sys) => {
1998
2033
  ${prompt} ${logger.green('rindo generate')} or ${logger.green('rindo g')}
1999
2034
 
2000
2035
  `);
2001
- // TODO: make this parameter no longer optional, remove the surrounding if statement
2002
- if (sys) {
2003
- await taskTelemetry(flags, sys, logger);
2004
- }
2036
+ await taskTelemetry(flags, sys, logger);
2005
2037
  console.log(`
2006
2038
  ${logger.bold('Examples:')}
2007
2039
 
@@ -2149,7 +2181,7 @@ const BLUE = `#3498db`;
2149
2181
  const run = async (init) => {
2150
2182
  const { args, logger, sys } = init;
2151
2183
  try {
2152
- const flags = parseFlags(args, sys);
2184
+ const flags = parseFlags(args);
2153
2185
  const task = flags.task;
2154
2186
  if (flags.debug || flags.verbose) {
2155
2187
  logger.setLevel('debug');
@@ -2161,7 +2193,7 @@ const run = async (init) => {
2161
2193
  sys.applyGlobalPatch(sys.getCurrentDirectory());
2162
2194
  }
2163
2195
  if (task === 'help' || flags.help) {
2164
- await taskHelp({ task: 'help', args }, logger, sys);
2196
+ await taskHelp(createConfigFlags({ task: 'help', args }), logger, sys);
2165
2197
  return;
2166
2198
  }
2167
2199
  startupLog(logger, task);
@@ -2187,9 +2219,7 @@ const run = async (init) => {
2187
2219
  startupLogVersion(logger, task, coreCompiler);
2188
2220
  loadedCompilerLog(sys, logger, flags, coreCompiler);
2189
2221
  if (task === 'info') {
2190
- await telemetryAction(sys, { flags: { task: 'info' }, logger }, coreCompiler, async () => {
2191
- await taskInfo(coreCompiler, sys, logger);
2192
- });
2222
+ taskInfo(coreCompiler, sys, logger);
2193
2223
  return;
2194
2224
  }
2195
2225
  const validated = await coreCompiler.loadConfig({
@@ -2222,14 +2252,27 @@ const run = async (init) => {
2222
2252
  }
2223
2253
  }
2224
2254
  };
2255
+ /**
2256
+ * Run a specified task
2257
+ * @param coreCompiler an instance of a minimal, bootstrap compiler for running the specified task
2258
+ * @param config a configuration for the Rindo project to apply to the task run
2259
+ * @param task the task to run
2260
+ * @param sys the {@link CompilerSystem} for interacting with the operating system
2261
+ * @public
2262
+ */
2225
2263
  const runTask = async (coreCompiler, config, task, sys) => {
2226
- var _a, _b;
2264
+ var _a, _b, _c;
2227
2265
  const logger = (_a = config.logger) !== null && _a !== void 0 ? _a : createLogger();
2228
- const strictConfig = { ...config, flags: (_b = { ...config.flags }) !== null && _b !== void 0 ? _b : { task }, logger };
2229
- strictConfig.outputTargets = strictConfig.outputTargets || [];
2266
+ const strictConfig = {
2267
+ ...config,
2268
+ flags: createConfigFlags((_b = config.flags) !== null && _b !== void 0 ? _b : { task }),
2269
+ logger,
2270
+ outputTargets: (_c = config.outputTargets) !== null && _c !== void 0 ? _c : [],
2271
+ sys: sys !== null && sys !== void 0 ? sys : coreCompiler.createSystem({ logger }),
2272
+ };
2230
2273
  switch (task) {
2231
2274
  case 'build':
2232
- await taskBuild(coreCompiler, strictConfig, sys);
2275
+ await taskBuild(coreCompiler, strictConfig);
2233
2276
  break;
2234
2277
  case 'docs':
2235
2278
  await taskDocs(coreCompiler, strictConfig);
@@ -2248,10 +2291,7 @@ const runTask = async (coreCompiler, config, task, sys) => {
2248
2291
  await taskServe(strictConfig);
2249
2292
  break;
2250
2293
  case 'telemetry':
2251
- // TODO: make this parameter no longer optional, remove the surrounding if statement
2252
- if (sys) {
2253
- await taskTelemetry(strictConfig.flags, sys, strictConfig.logger);
2254
- }
2294
+ await taskTelemetry(strictConfig.flags, sys, strictConfig.logger);
2255
2295
  break;
2256
2296
  case 'version':
2257
2297
  console.log(coreCompiler.version);
package/cli/index.d.ts CHANGED
@@ -12,5 +12,5 @@ export declare function run(init: CliInitOptions): Promise<void>;
12
12
  * @param task The task command to run, such as `build`.
13
13
  */
14
14
  export declare function runTask(coreCompiler: any, config: Config, task: TaskCommand): Promise<void>;
15
- export declare function parseFlags(args: string[], sys?: CompilerSystem): ConfigFlags;
15
+ export declare function parseFlags(args: string[], _sys?: CompilerSystem): ConfigFlags;
16
16
  export { CompilerSystem, Config, ConfigFlags, Logger, TaskCommand };