qunitx-cli 0.5.3 → 0.5.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.
@@ -1,11 +1,8 @@
1
1
  import fs from 'node:fs/promises';
2
- import { dirname } from 'node:path';
3
- import { fileURLToPath } from 'node:url';
4
2
  import kleur from 'kleur';
5
3
  import findProjectRoot from '../utils/find-project-root.js';
6
4
  import pathExists from '../utils/path-exists.js';
7
-
8
- const __dirname = dirname(fileURLToPath(import.meta.url));
5
+ import readBoilerplate from '../utils/read-boilerplate.js';
9
6
 
10
7
  export default async function () {
11
8
  const projectRoot = await findProjectRoot();
@@ -19,13 +16,13 @@ export default async function () {
19
16
  return console.log(`${path} already exists!`);
20
17
  }
21
18
 
22
- const testJSContent = await fs.readFile(`${__dirname}/../boilerplates/test.js`);
19
+ const testJSContent = await readBoilerplate('test.js');
23
20
  const targetFolderPaths = path.split('/');
24
21
 
25
22
  targetFolderPaths.pop();
26
23
 
27
24
  await fs.mkdir(targetFolderPaths.join('/'), { recursive: true });
28
- await fs.writeFile(path, testJSContent.toString().replace('{{moduleName}}', moduleName));
25
+ await fs.writeFile(path, testJSContent.replace('{{moduleName}}', moduleName));
29
26
 
30
27
  console.log(kleur.green(`${path} written`));
31
28
  }
@@ -1,14 +1,11 @@
1
- import fs from 'node:fs/promises';
2
- import { dirname } from 'node:path';
3
- import { fileURLToPath } from 'node:url';
4
1
  import kleur from 'kleur';
2
+ import pkg from '../../package.json' with { type: 'json' };
5
3
 
6
- const __dirname = dirname(fileURLToPath(import.meta.url));
7
4
  const highlight = (text) => kleur.magenta().bold(text);
8
5
  const color = (text) => kleur.blue(text);
9
6
 
10
- export default async function () {
11
- const config = JSON.parse(await fs.readFile(`${__dirname}/../../package.json`));
7
+ export default function () {
8
+ const config = pkg;
12
9
 
13
10
  console.log(`${highlight('[qunitx v' + config.version + '] Usage:')} qunitx ${color('[targets] --$flags')}
14
11
 
@@ -1,11 +1,9 @@
1
1
  import fs from 'node:fs/promises';
2
- import path, { dirname } from 'node:path';
3
- import { fileURLToPath } from 'node:url';
2
+ import path from 'node:path';
4
3
  import findProjectRoot from '../utils/find-project-root.js';
5
4
  import pathExists from '../utils/path-exists.js';
6
5
  import defaultProjectConfigValues from '../boilerplates/default-project-config-values.js';
7
-
8
- const __dirname = dirname(fileURLToPath(import.meta.url));
6
+ import readBoilerplate from '../utils/read-boilerplate.js';
9
7
 
10
8
  export default async function () {
11
9
  const projectRoot = await findProjectRoot();
@@ -34,7 +32,7 @@ export default async function () {
34
32
  }
35
33
 
36
34
  async function writeTestsHTML(projectRoot, newQunitxConfig, oldPackageJSON) {
37
- const testHTMLTemplateBuffer = await fs.readFile(`${__dirname}/../boilerplates/setup/tests.hbs`);
35
+ const testHTMLTemplateBuffer = await readBoilerplate('setup/tests.hbs');
38
36
 
39
37
  return await Promise.all(
40
38
  newQunitxConfig.htmlPaths.map(async (htmlPath) => {
@@ -47,9 +45,10 @@ async function writeTestsHTML(projectRoot, newQunitxConfig, oldPackageJSON) {
47
45
  targetDirectory,
48
46
  `${projectRoot}/${newQunitxConfig.output}/tests.js`,
49
47
  );
50
- const testHTMLTemplate = testHTMLTemplateBuffer
51
- .toString()
52
- .replace('{{applicationName}}', oldPackageJSON.name);
48
+ const testHTMLTemplate = testHTMLTemplateBuffer.replace(
49
+ '{{applicationName}}',
50
+ oldPackageJSON.name,
51
+ );
53
52
 
54
53
  await fs.mkdir(targetDirectory, { recursive: true });
55
54
  await fs.writeFile(targetPath, testHTMLTemplate);
@@ -69,11 +68,9 @@ async function rewritePackageJSON(projectRoot, newQunitxConfig, oldPackageJSON)
69
68
  async function writeTSConfigIfNeeded(projectRoot) {
70
69
  const targetPath = `${projectRoot}/tsconfig.json`;
71
70
  if (!(await pathExists(targetPath))) {
72
- const tsConfigTemplateBuffer = await fs.readFile(
73
- `${__dirname}/../boilerplates/setup/tsconfig.json`,
74
- );
71
+ const tsConfigTemplate = await readBoilerplate('setup/tsconfig.json');
75
72
 
76
- await fs.writeFile(targetPath, tsConfigTemplateBuffer);
73
+ await fs.writeFile(targetPath, tsConfigTemplate);
77
74
 
78
75
  console.log(`${targetPath} written`);
79
76
  }
@@ -1,14 +1,10 @@
1
1
  import fs from 'node:fs/promises';
2
- import { dirname } from 'node:path';
3
- import { fileURLToPath } from 'node:url';
4
2
  import kleur from 'kleur';
5
3
  import esbuild from 'esbuild';
6
4
  import timeCounter from '../../utils/time-counter.js';
7
5
  import runUserModule from '../../utils/run-user-module.js';
8
6
  import TAPDisplayFinalResult from '../../tap/display-final-result.js';
9
7
 
10
- const __dirname = dirname(fileURLToPath(import.meta.url));
11
-
12
8
  class BundleError extends Error {
13
9
  constructor(message) {
14
10
  super(message);
@@ -1,6 +1,5 @@
1
1
  import fs from 'node:fs/promises';
2
- import { normalize, dirname } from 'node:path';
3
- import { fileURLToPath } from 'node:url';
2
+ import { normalize } from 'node:path';
4
3
  import { availableParallelism } from 'node:os';
5
4
  import Puppeteer from 'puppeteer';
6
5
  import kleur from 'kleur';
@@ -14,8 +13,7 @@ import writeOutputStaticFiles from '../setup/write-output-static-files.js';
14
13
  import timeCounter from '../utils/time-counter.js';
15
14
  import TAPDisplayFinalResult from '../tap/display-final-result.js';
16
15
  import findChrome from '../utils/find-chrome.js';
17
-
18
- const __dirname = dirname(fileURLToPath(import.meta.url));
16
+ import readBoilerplate from '../utils/read-boilerplate.js';
19
17
 
20
18
  export default async function (config) {
21
19
  const cachedContent = await buildCachedContent(config, config.htmlPaths);
@@ -194,7 +192,7 @@ async function addCachedContentMainHTML(projectRoot, cachedContent) {
194
192
  html: cachedContent.dynamicContentHTMLs[mainHTMLPath],
195
193
  };
196
194
  } else {
197
- const html = (await fs.readFile(`${__dirname}/../boilerplates/setup/tests.hbs`)).toString();
195
+ const html = await readBoilerplate('setup/tests.hbs');
198
196
  cachedContent.mainHTML = { filePath: `${projectRoot}/test/tests.html`, html };
199
197
  cachedContent.assets.add(`${projectRoot}/node_modules/qunitx/vendor/qunit.css`);
200
198
  }
@@ -0,0 +1,11 @@
1
+ import { isSea, getAsset } from 'node:sea';
2
+ import fs from 'node:fs/promises';
3
+ import { dirname, join } from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+
6
+ const __dirname = dirname(fileURLToPath(import.meta.url));
7
+
8
+ export default async function readBoilerplate(relativePath) {
9
+ if (isSea()) return getAsset(relativePath, 'utf8');
10
+ return (await fs.readFile(join(__dirname, '../boilerplates', relativePath))).toString();
11
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "qunitx-cli",
3
3
  "type": "module",
4
- "version": "0.5.3",
4
+ "version": "0.5.4",
5
5
  "description": "Browser runner for QUnitx: run your qunitx tests in google-chrome",
6
6
  "main": "cli.js",
7
7
  "author": "Izel Nakri",