js-build-tools 4.0.12 → 4.1.1

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 (49) hide show
  1. package/README.md +0 -120
  2. package/dist/build.js +1 -3
  3. package/dist/build.min.js +1 -1
  4. package/dist/bundle.js +1 -2
  5. package/dist/bundle.min.js +1 -1
  6. package/dist/bundleLint.js +1 -2
  7. package/dist/bundleLint.min.js +1 -1
  8. package/dist/bundleMinify.js +1 -2
  9. package/dist/bundleMinify.min.js +1 -1
  10. package/dist/copyFonts.js +0 -1
  11. package/dist/copyFonts.min.js +1 -1
  12. package/dist/default.js +1 -5
  13. package/dist/default.min.js +1 -1
  14. package/dist/distLint.js +0 -1
  15. package/dist/distLint.min.js +1 -1
  16. package/dist/distMinify.js +0 -1
  17. package/dist/distMinify.min.js +1 -1
  18. package/dist/partials/addToReadme.js +0 -1
  19. package/dist/partials/beginWatcher.js +0 -1
  20. package/dist/partials/clean.js +0 -1
  21. package/dist/partials/distFor.js +6 -14
  22. package/dist/partials/distForSrc.js +1 -5
  23. package/dist/partials/distSeries.js +1 -5
  24. package/dist/partials/imagesFor.js +7 -12
  25. package/dist/partials/readmeTemplate.js +0 -1
  26. package/dist/partials/runOnChange.js +3 -7
  27. package/dist/partials/sassFor.js +4 -9
  28. package/dist/partials/tsFor.js +86 -27
  29. package/dist/test-helpers/setUp.js +20 -22
  30. package/dist/testFull.js +20 -22
  31. package/dist/testFull.min.js +1 -1
  32. package/dist/testHelpers.js +0 -1
  33. package/dist/testHelpers.min.js +1 -1
  34. package/dist/testQuick.js +22 -24
  35. package/dist/testQuick.min.js +1 -1
  36. package/dist/utilities/dotGet.js +2 -6
  37. package/dist/utilities/dotNotate.js +6 -15
  38. package/dist/utilities/dotSet.js +2 -4
  39. package/dist/watchTest.js +0 -1
  40. package/dist/watchTest.min.js +1 -1
  41. package/functions/build.test.mjs +24 -0
  42. package/functions/partials/distFor.test.mjs +41 -10
  43. package/functions/partials/tsFor.mjs +73 -9
  44. package/functions/partials/tsFor.test.mjs +31 -1
  45. package/functions/testFull.mjs +2 -2
  46. package/functions/testFull.test.mjs +2 -2
  47. package/functions/testQuick.mjs +2 -2
  48. package/functions/testQuick.test.mjs +2 -2
  49. package/package.json +10 -8
@@ -1,34 +1,93 @@
1
- "use strict";
2
-
3
- require("core-js/modules/esnext.weak-map.delete-all.js");
4
- require("core-js/modules/web.dom-collections.iterator.js");
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.tsFor = void 0;
9
- var _gulp = require("gulp");
10
- var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
11
- var _gulpTypescript = _interopRequireDefault(require("gulp-typescript"));
12
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
1
+ "use strict";
2
+
3
+ require("core-js/modules/esnext.weak-map.delete-all.js");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.tsFor = void 0;
8
+ var _gulp = require("gulp");
9
+ var _nodePath = _interopRequireDefault(require("node:path"));
10
+ var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
11
+ var _typescript = _interopRequireDefault(require("typescript"));
12
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
13
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
+ // gulp-ts-compile ships ESM-only (no CJS build - see its own package.json) since it's meant to be consumed by
15
+ // gulpfiles running under a real ESM loader, same as this project's own gulpfile.mjs does. This project also
16
+ // compiles itself to a CommonJS build (dist/*.js, this file's own compiled counterpart) for consumers using
17
+ // require() though, and even a dynamic `import()` gets downleveled by babel's CommonJS transform into a
18
+ // require() call - which can't load a real ES module. Hiding the import() call inside a Function constructor is
19
+ // the standard escape hatch: babel can't see (and so can't rewrite) an import expression that only exists as a
20
+ // runtime-evaluated string, so it survives as a genuine dynamic import, capable of loading gulp-ts-compile from
21
+ // either build.
22
+ const importGulpTsCompile = new Function('return import(\'gulp-ts-compile\')');
23
+
24
+ /**
25
+ * Wrap a stream in a promise that resolves once it finishes writing.
26
+ * @memberOf module:partials
27
+ * @param {import('node:stream').Stream} stream
28
+ * @returns {Promise<void>}
29
+ */
30
+ const streamToPromise = stream => new Promise((resolve, reject) => {
31
+ stream.on('finish', resolve);
32
+ stream.on('error', reject);
33
+ });
34
+
35
+ /**
36
+ * Read a tsconfig.json file into real typescript.CompilerOptions values, using only TypeScript's stable, current,
37
+ * public config-reading API (the same one `tsc --project` itself uses internally) - never
38
+ * `ts.convertCompilerOptionsFromJson`, which is exactly the kind of internal/legacy surface that broke
39
+ * gulp-typescript when a removed API call started throwing under TypeScript 7.
40
+ * @memberOf module:partials
41
+ * @param {string} configPath - Path to a tsconfig.json file.
42
+ * @returns {import('typescript').CompilerOptions}
43
+ */
44
+ const readCompilerOptions = configPath => {
45
+ const configFile = _typescript.default.readConfigFile(configPath, _typescript.default.sys.readFile);
46
+ const parsedConfig = _typescript.default.parseJsonConfigFileContent(configFile.config, _typescript.default.sys, _nodePath.default.dirname(configPath));
47
+ return parsedConfig.options;
48
+ };
49
+
14
50
  /**
15
51
  * Starting at the source directory, find all the ts files and convert them into the distribution directory.
16
52
  * @memberOf module:partials
17
53
  * @param {string|array} [srcPath='']
18
54
  * @param {string} [distPath='']
55
+ * @param {function(): Promise<Function>} [loadTsCompile] - Resolves the `gulp-ts-compile` default export. Real
56
+ * callers should never need to pass this - it exists so tests can inject a stand-in compiler, sidestepping the
57
+ * genuine dynamic `import()` above that this project's current CommonJS-transform-based Jest setup cannot
58
+ * execute without a broader (and riskier) migration to Jest's native ESM support. gulp-ts-compile's own test
59
+ * suite already covers real TypeScript-compile correctness - this function's own tests only need to verify its
60
+ * config resolution and stream wiring.
19
61
  * @returns {Function}
20
- * @see `https://www.typescriptlang.org/docs/handbook/gulp.html` for more info
21
- */
22
- const tsFor = function () {
23
- let srcPath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : gulpConfig.get('typescript.from');
24
- let distPath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : gulpConfig.get('typescript.to');
25
- if (gulpConfig.get('typescript.enabled') === false) {
26
- return () => {};
27
- }
28
- const declarationProject = _gulpTypescript.default.createProject(gulpConfig.get('typescript.config'));
29
- const tsProject = _gulpTypescript.default.createProject(gulpConfig.get('typescript.config'));
30
- const makeDeclarations = () => (0, _gulp.src)(srcPath).pipe(declarationProject()).dts.pipe((0, _gulp.dest)(distPath));
31
- const compileJS = () => (0, _gulp.src)(srcPath).pipe(tsProject()).js.pipe((0, _gulp.dest)(distPath));
32
- return (0, _gulp.parallel)(makeDeclarations, compileJS);
33
- };
62
+ */
63
+ const tsFor = (srcPath = gulpConfig.get('typescript.from'), distPath = gulpConfig.get('typescript.to'), loadTsCompile = () => importGulpTsCompile().then(({
64
+ default: tsCompile
65
+ }) => tsCompile)) => {
66
+ if (gulpConfig.get('typescript.enabled') === false) {
67
+ return () => {};
68
+ }
69
+ const configPath = gulpConfig.get('typescript.config');
70
+ // When no tsconfig.json is configured, target/module are pinned explicitly rather than left for TypeScript's
71
+ // own compiler defaults - those defaults have already shifted once across a TypeScript version bump in this
72
+ // project's own history (silently changing whether output keeps `const`/`let` or downlevels to `var`), and
73
+ // pinning them keeps this task's output stable across future TypeScript upgrades too. ES5/CommonJS matches
74
+ // what the downstream babel/browserify bundling pipeline has always assumed it receives.
75
+ const compilerOptions = configPath ? readCompilerOptions(configPath) : {
76
+ declaration: true,
77
+ target: _typescript.default.ScriptTarget.ES5,
78
+ module: _typescript.default.ModuleKind.CommonJS,
79
+ esModuleInterop: false
80
+ };
81
+ // Accepts gulp's own callback-style task convention (an optional `done`, called once finished) rather than
82
+ // just returning a Promise, since callers may invoke the returned function directly with a callback instead
83
+ // of relying on gulp's own runner to observe a returned Promise.
84
+ return done => {
85
+ const compile = async () => {
86
+ const tsCompile = await loadTsCompile();
87
+ const tsResult = (0, _gulp.src)(srcPath).pipe(tsCompile(compilerOptions));
88
+ await Promise.all([streamToPromise(tsResult.dts.pipe((0, _gulp.dest)(distPath))), streamToPromise(tsResult.js.pipe((0, _gulp.dest)(distPath)))]);
89
+ };
90
+ return typeof done === 'function' ? compile().then(() => done(), done) : compile();
91
+ };
92
+ };
34
93
  exports.tsFor = tsFor;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  require("core-js/modules/esnext.weak-map.delete-all.js");
4
- require("core-js/modules/web.dom-collections.iterator.js");
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
@@ -56,41 +55,40 @@ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r
56
55
  // Import the configurations and override some of them to direct to the temp directory.
57
56
 
58
57
  let tempDir = 'test-temp/';
59
- let srcPath = "".concat(tempDir, "src");
58
+ let srcPath = `${tempDir}src`;
60
59
 
61
60
  /**
62
61
  * Update the gulp configurations with the test data. Set the test directory where temp files will be created for testing.
63
62
  * @memberOf module:testHelpers
64
63
  * @param {string} testDir
65
64
  */
66
- const setDefaults = function () {
67
- let testDir = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'test-temp';
68
- tempDir = "".concat(testDir, "/");
69
- srcPath = "".concat(tempDir, "src");
65
+ const setDefaults = (testDir = 'test-temp') => {
66
+ tempDir = `${testDir}/`;
67
+ srcPath = `${tempDir}src`;
70
68
  _testFilesystem.setUp.setDefaults(tempDir);
71
- const distPath = "".concat(tempDir, "dist");
72
- const browserPath = "".concat(tempDir, "browser");
73
- const sassPath = "".concat(tempDir, "sass");
74
- gulpConfig.set('browser.from', "".concat(distPath, "/**/*.js"));
69
+ const distPath = `${tempDir}dist`;
70
+ const browserPath = `${tempDir}browser`;
71
+ const sassPath = `${tempDir}sass`;
72
+ gulpConfig.set('browser.from', `${distPath}/**/*.js`);
75
73
  gulpConfig.set('browser.to', browserPath);
76
74
  gulpConfig.set('cleanPaths', [distPath, browserPath]);
77
- gulpConfig.set('dist.from', "".concat(srcPath, "/**/!(*.test).js"));
78
- gulpConfig.set('dist.main', "".concat(distPath, "/main"));
75
+ gulpConfig.set('dist.from', `${srcPath}/**/!(*.test).js`);
76
+ gulpConfig.set('dist.main', `${distPath}/main`);
79
77
  gulpConfig.set('dist.to', distPath);
80
- gulpConfig.set('fonts.from', "".concat(srcPath, "/fonts/**/*"));
81
- gulpConfig.set('fonts.to', "".concat(browserPath, "/fonts"));
82
- gulpConfig.set('images.from', "".concat(srcPath, "/img/**/*.+(png|jpg|jpeg|gif|svg)"));
83
- gulpConfig.set('images.to', "".concat(browserPath, "/img"));
84
- gulpConfig.set('readme.template', "".concat(tempDir, "MAIN.md"));
78
+ gulpConfig.set('fonts.from', `${srcPath}/fonts/**/*`);
79
+ gulpConfig.set('fonts.to', `${browserPath}/fonts`);
80
+ gulpConfig.set('images.from', `${srcPath}/img/**/*.+(png|jpg|jpeg|gif|svg)`);
81
+ gulpConfig.set('images.to', `${browserPath}/img`);
82
+ gulpConfig.set('readme.template', `${tempDir}MAIN.md`);
85
83
  gulpConfig.set('readme.to', tempDir);
86
- gulpConfig.set('readme.from', "".concat(srcPath, "/**/!(*.test).js"));
84
+ gulpConfig.set('readme.from', `${srcPath}/**/!(*.test).js`);
87
85
  gulpConfig.set('rootPath', tempDir);
88
- gulpConfig.set('sass.from', "".concat(sassPath, "/**/*.+(scss|sass)"));
86
+ gulpConfig.set('sass.from', `${sassPath}/**/*.+(scss|sass)`);
89
87
  gulpConfig.set('sass.path', sassPath);
90
- gulpConfig.set('sass.to', "".concat(browserPath, "/css"));
88
+ gulpConfig.set('sass.to', `${browserPath}/css`);
91
89
  gulpConfig.set('srcPath', srcPath);
92
- gulpConfig.set('typescript.from', "".concat(srcPath, "/**/*.ts"));
90
+ gulpConfig.set('typescript.from', `${srcPath}/**/*.ts`);
93
91
  gulpConfig.set('typescript.to', distPath);
94
- gulpConfig.set('test.watch', "".concat(srcPath, "/**/*.js"));
92
+ gulpConfig.set('test.watch', `${srcPath}/**/*.js`);
95
93
  };
96
94
  exports.setDefaults = setDefaults;
package/dist/testFull.js CHANGED
@@ -1,27 +1,25 @@
1
- 'use strict'
2
-
3
- require('core-js/modules/esnext.weak-map.delete-all.js')
4
- require('core-js/modules/web.dom-collections.iterator.js')
5
- Object.defineProperty(exports, '__esModule', {
6
- value: true
7
- })
8
- exports.testFull = void 0
9
- var gulpConfig = _interopRequireWildcard(require('../gulp.config.js'))
10
- var _jest = _interopRequireDefault(require('jest'))
11
- function _interopRequireDefault (e) { return e && e.__esModule ? e : { default: e } }
12
- function _interopRequireWildcard (e, t) { if (typeof WeakMap === 'function') var r = new WeakMap(); var n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o; var i; var f = { __proto__: null, default: e }; if (e === null || typeof e !== 'object' && typeof e !== 'function') return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f) } for (const t in e) t !== 'default' && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f })(e, t) }
1
+ 'use strict'
2
+
3
+ require('core-js/modules/esnext.weak-map.delete-all.js')
4
+ Object.defineProperty(exports, '__esModule', {
5
+ value: true
6
+ })
7
+ exports.testFull = void 0
8
+ var gulpConfig = _interopRequireWildcard(require('../gulp.config.js'))
9
+ var _jest = require('jest')
10
+ function _interopRequireWildcard (e, t) { if (typeof WeakMap === 'function') var r = new WeakMap(); var n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o; var i; var f = { __proto__: null, default: e }; if (e === null || typeof e !== 'object' && typeof e !== 'function') return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f) } for (const t in e) t !== 'default' && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f })(e, t) }
13
11
  /**
14
12
  * Run all tests with jest.
15
13
  * Configure where tests are located by using 'testPath'.
16
14
  * @memberOf module:js-build-tools
17
15
  * @returns {Promise<*>}
18
- */
19
- const testFull = () => {
20
- let testPath = gulpConfig.get('test.path')
21
- if (!Array.isArray(testPath)) {
22
- // The testPath must be an array of strings
23
- testPath = [testPath]
24
- }
25
- return _jest.default.runCLI(gulpConfig.get('test.options'), testPath)
26
- }
27
- exports.testFull = testFull
16
+ */
17
+ const testFull = () => {
18
+ let testPath = gulpConfig.get('test.path')
19
+ if (!Array.isArray(testPath)) {
20
+ // The testPath must be an array of strings
21
+ testPath = [testPath]
22
+ }
23
+ return (0, _jest.runCLI)(gulpConfig.get('test.options'), testPath)
24
+ }
25
+ exports.testFull = testFull
@@ -1 +1 @@
1
- "use strict";require("core-js/modules/esnext.weak-map.delete-all.js"),require("core-js/modules/web.dom-collections.iterator.js"),Object.defineProperty(exports,"__esModule",{value:!0}),exports.testFull=void 0;var gulpConfig=_interopRequireWildcard(require("../gulp.config.js")),_jest=_interopRequireDefault(require("jest"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _interopRequireWildcard(e,t){if("function"==typeof WeakMap)var r=new WeakMap,o=new WeakMap;return(_interopRequireWildcard=function(e,t){if(!t&&e&&e.__esModule)return e;var u,i,n={__proto__:null,default:e};if(null===e||"object"!=typeof e&&"function"!=typeof e)return n;if(u=t?o:r){if(u.has(e))return u.get(e);u.set(e,n)}for(const t in e)"default"!==t&&{}.hasOwnProperty.call(e,t)&&((i=(u=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,t))&&(i.get||i.set)?u(n,t,i):n[t]=e[t]);return n})(e,t)}const testFull=()=>{let e=gulpConfig.get("test.path");return Array.isArray(e)||(e=[e]),_jest.default.runCLI(gulpConfig.get("test.options"),e)};exports.testFull=testFull;
1
+ "use strict";require("core-js/modules/esnext.weak-map.delete-all.js"),Object.defineProperty(exports,"__esModule",{value:!0}),exports.testFull=void 0;var gulpConfig=_interopRequireWildcard(require("../gulp.config.js")),_jest=require("jest");function _interopRequireWildcard(e,t){if("function"==typeof WeakMap)var r=new WeakMap,n=new WeakMap;return(_interopRequireWildcard=function(e,t){if(!t&&e&&e.__esModule)return e;var o,u,i={__proto__:null,default:e};if(null===e||"object"!=typeof e&&"function"!=typeof e)return i;if(o=t?n:r){if(o.has(e))return o.get(e);o.set(e,i)}for(const t in e)"default"!==t&&{}.hasOwnProperty.call(e,t)&&((u=(o=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,t))&&(u.get||u.set)?o(i,t,u):i[t]=e[t]);return i})(e,t)}const testFull=()=>{let e=gulpConfig.get("test.path");return Array.isArray(e)||(e=[e]),(0,_jest.runCLI)(gulpConfig.get("test.options"),e)};exports.testFull=testFull;
@@ -1,7 +1,6 @@
1
1
  'use strict'
2
2
 
3
3
  require('core-js/modules/esnext.weak-map.delete-all.js')
4
- require('core-js/modules/web.dom-collections.iterator.js')
5
4
  Object.defineProperty(exports, '__esModule', {
6
5
  value: true
7
6
  })
@@ -1 +1 @@
1
- "use strict";require("core-js/modules/esnext.weak-map.delete-all.js"),require("core-js/modules/web.dom-collections.iterator.js"),Object.defineProperty(exports,"__esModule",{value:!0}),exports.testHelpers=void 0;var _testHelpers=_interopRequireWildcard(require("./test-helpers/setUp.js"));function _interopRequireWildcard(e,t){if("function"==typeof WeakMap)var r=new WeakMap,o=new WeakMap;return(_interopRequireWildcard=function(e,t){if(!t&&e&&e.__esModule)return e;var s,i,n={__proto__:null,default:e};if(null===e||"object"!=typeof e&&"function"!=typeof e)return n;if(s=t?o:r){if(s.has(e))return s.get(e);s.set(e,n)}for(const t in e)"default"!==t&&{}.hasOwnProperty.call(e,t)&&((i=(s=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,t))&&(i.get||i.set)?s(n,t,i):n[t]=e[t]);return n})(e,t)}exports.testHelpers=_testHelpers;
1
+ "use strict";require("core-js/modules/esnext.weak-map.delete-all.js"),Object.defineProperty(exports,"__esModule",{value:!0}),exports.testHelpers=void 0;var _testHelpers=_interopRequireWildcard(require("./test-helpers/setUp.js"));function _interopRequireWildcard(e,t){if("function"==typeof WeakMap)var r=new WeakMap,s=new WeakMap;return(_interopRequireWildcard=function(e,t){if(!t&&e&&e.__esModule)return e;var o,n,i={__proto__:null,default:e};if(null===e||"object"!=typeof e&&"function"!=typeof e)return i;if(o=t?s:r){if(o.has(e))return o.get(e);o.set(e,i)}for(const t in e)"default"!==t&&{}.hasOwnProperty.call(e,t)&&((n=(o=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,t))&&(n.get||n.set)?o(i,t,n):i[t]=e[t]);return i})(e,t)}exports.testHelpers=_testHelpers;
package/dist/testQuick.js CHANGED
@@ -1,29 +1,27 @@
1
- 'use strict'
2
-
3
- require('core-js/modules/esnext.weak-map.delete-all.js')
4
- require('core-js/modules/web.dom-collections.iterator.js')
5
- Object.defineProperty(exports, '__esModule', {
6
- value: true
7
- })
8
- exports.testQuick = void 0
9
- var gulpConfig = _interopRequireWildcard(require('../gulp.config.js'))
10
- var _jest = _interopRequireDefault(require('jest'))
11
- function _interopRequireDefault (e) { return e && e.__esModule ? e : { default: e } }
12
- function _interopRequireWildcard (e, t) { if (typeof WeakMap === 'function') var r = new WeakMap(); var n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o; var i; var f = { __proto__: null, default: e }; if (e === null || typeof e !== 'object' && typeof e !== 'function') return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f) } for (const t in e) t !== 'default' && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f })(e, t) }
1
+ 'use strict'
2
+
3
+ require('core-js/modules/esnext.weak-map.delete-all.js')
4
+ Object.defineProperty(exports, '__esModule', {
5
+ value: true
6
+ })
7
+ exports.testQuick = void 0
8
+ var gulpConfig = _interopRequireWildcard(require('../gulp.config.js'))
9
+ var _jest = require('jest')
10
+ function _interopRequireWildcard (e, t) { if (typeof WeakMap === 'function') var r = new WeakMap(); var n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o; var i; var f = { __proto__: null, default: e }; if (e === null || typeof e !== 'object' && typeof e !== 'function') return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f) } for (const t in e) t !== 'default' && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f })(e, t) }
13
11
  /**
14
12
  * Run the Jest tests for files which have been modified (based on git status).
15
13
  * Configure where tests are located by using 'testPath'.
16
14
  * @memberOf module:js-build-tools
17
15
  * @returns {Promise<*>}
18
- */
19
- const testQuick = () => {
20
- let testPath = gulpConfig.get('test.path')
21
- if (!Array.isArray(testPath)) {
22
- // The testPath must be an array of strings
23
- testPath = [testPath]
24
- }
25
- return _jest.default.runCLI({
26
- onlyChanged: true
27
- }, testPath)
28
- }
29
- exports.testQuick = testQuick
16
+ */
17
+ const testQuick = () => {
18
+ let testPath = gulpConfig.get('test.path')
19
+ if (!Array.isArray(testPath)) {
20
+ // The testPath must be an array of strings
21
+ testPath = [testPath]
22
+ }
23
+ return (0, _jest.runCLI)({
24
+ onlyChanged: true
25
+ }, testPath)
26
+ }
27
+ exports.testQuick = testQuick
@@ -1 +1 @@
1
- "use strict";require("core-js/modules/esnext.weak-map.delete-all.js"),require("core-js/modules/web.dom-collections.iterator.js"),Object.defineProperty(exports,"__esModule",{value:!0}),exports.testQuick=void 0;var gulpConfig=_interopRequireWildcard(require("../gulp.config.js")),_jest=_interopRequireDefault(require("jest"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _interopRequireWildcard(e,t){if("function"==typeof WeakMap)var r=new WeakMap,u=new WeakMap;return(_interopRequireWildcard=function(e,t){if(!t&&e&&e.__esModule)return e;var i,o,n={__proto__:null,default:e};if(null===e||"object"!=typeof e&&"function"!=typeof e)return n;if(i=t?u:r){if(i.has(e))return i.get(e);i.set(e,n)}for(const t in e)"default"!==t&&{}.hasOwnProperty.call(e,t)&&((o=(i=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,t))&&(o.get||o.set)?i(n,t,o):n[t]=e[t]);return n})(e,t)}const testQuick=()=>{let e=gulpConfig.get("test.path");return Array.isArray(e)||(e=[e]),_jest.default.runCLI({onlyChanged:!0},e)};exports.testQuick=testQuick;
1
+ "use strict";require("core-js/modules/esnext.weak-map.delete-all.js"),Object.defineProperty(exports,"__esModule",{value:!0}),exports.testQuick=void 0;var gulpConfig=_interopRequireWildcard(require("../gulp.config.js")),_jest=require("jest");function _interopRequireWildcard(e,t){if("function"==typeof WeakMap)var r=new WeakMap,i=new WeakMap;return(_interopRequireWildcard=function(e,t){if(!t&&e&&e.__esModule)return e;var n,o,u={__proto__:null,default:e};if(null===e||"object"!=typeof e&&"function"!=typeof e)return u;if(n=t?i:r){if(n.has(e))return n.get(e);n.set(e,u)}for(const t in e)"default"!==t&&{}.hasOwnProperty.call(e,t)&&((o=(n=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,t))&&(o.get||o.set)?n(u,t,o):u[t]=e[t]);return u})(e,t)}const testQuick=()=>{let e=gulpConfig.get("test.path");return Array.isArray(e)||(e=[e]),(0,_jest.runCLI)({onlyChanged:!0},e)};exports.testQuick=testQuick;
@@ -15,10 +15,7 @@ var _strBefore = require("./strBefore.js");
15
15
  * @param {string|null} [defaultValue=null] - The default value to return if the property is not found
16
16
  * @returns {*} The value of the property
17
17
  */
18
- const dotGet = function () {
19
- let arrayObject = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
20
- let dotNotation = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
21
- let defaultValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
18
+ const dotGet = (arrayObject = {}, dotNotation = '', defaultValue = null) => {
22
19
  if (!dotNotation) {
23
20
  return arrayObject;
24
21
  }
@@ -43,8 +40,7 @@ const dotGet = function () {
43
40
  return result;
44
41
  }
45
42
  if (lastKey) {
46
- var _arrayObject$dotNotat;
47
- return (_arrayObject$dotNotat = arrayObject[dotNotation]) !== null && _arrayObject$dotNotat !== void 0 ? _arrayObject$dotNotat : defaultValue;
43
+ return arrayObject[dotNotation] ?? defaultValue;
48
44
  }
49
45
  if (typeof arrayObject[key] === 'undefined') {
50
46
  return defaultValue;
@@ -4,9 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.dotNotate = void 0;
7
- require("core-js/modules/es.regexp.constructor.js");
8
- require("core-js/modules/es.regexp.exec.js");
9
- require("core-js/modules/es.string.replace.js");
10
7
  require("core-js/modules/esnext.iterator.constructor.js");
11
8
  require("core-js/modules/esnext.iterator.map.js");
12
9
  var _isObject = require("./isObject.js");
@@ -15,8 +12,7 @@ var _isObject = require("./isObject.js");
15
12
  * @param {Array.<string>} [retainObjects=[]] - An array of keys to retain as objects
16
13
  * @returns {Function} The dot-notated array
17
14
  */
18
- const handleRetainObjects = function () {
19
- let retainObjects = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
15
+ const handleRetainObjects = (retainObjects = []) => {
20
16
  if (!retainObjects.length) {
21
17
  /**
22
18
  * Bypass the test function if there are no retainObjects.
@@ -25,7 +21,7 @@ const handleRetainObjects = function () {
25
21
  return (currentKey, value, results) => false;
26
22
  }
27
23
  retainObjects = retainObjects.map(key => key.replace('\.', '\\.'));
28
- const retainRegex = new RegExp("(".concat(retainObjects.join('|'), ")$"));
24
+ const retainRegex = new RegExp(`(${retainObjects.join('|')})$`);
29
25
  /**
30
26
  * Test if a key should be retained as an object.
31
27
  * @param {string} currentKey - The key to test
@@ -50,17 +46,15 @@ const handleRetainObjects = function () {
50
46
  * @param {Object<string, *>} [results={}] - The final notated object to return
51
47
  * @returns {Object<string, *>} The dot-notated object
52
48
  */
53
- const performDotNotate = function (arrayObject, didRetain) {
54
- let prepend = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
55
- let results = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
49
+ const performDotNotate = (arrayObject, didRetain, prepend = '', results = {}) => {
56
50
  for (let key in arrayObject) {
57
51
  const value = arrayObject[key];
58
- const currentKey = "".concat(prepend).concat(key);
52
+ const currentKey = `${prepend}${key}`;
59
53
  if (didRetain(currentKey, value, results)) {
60
54
  continue;
61
55
  }
62
56
  if ((0, _isObject.isObject)(value)) {
63
- performDotNotate(value, didRetain, "".concat(currentKey, "."), results);
57
+ performDotNotate(value, didRetain, `${currentKey}.`, results);
64
58
  continue;
65
59
  }
66
60
  results[currentKey] = value;
@@ -75,8 +69,5 @@ const performDotNotate = function (arrayObject, didRetain) {
75
69
  * @param {Array.<string>} [retainObjects=[]] - An array of keys to retain as objects
76
70
  * @returns {Object<string, *>} The dot-notated object
77
71
  */
78
- const dotNotate = function (arrayObject) {
79
- let retainObjects = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
80
- return performDotNotate(arrayObject, handleRetainObjects(retainObjects));
81
- };
72
+ const dotNotate = (arrayObject, retainObjects = []) => performDotNotate(arrayObject, handleRetainObjects(retainObjects));
82
73
  exports.dotNotate = dotNotate;
@@ -15,9 +15,7 @@ var _strBefore = require("./strBefore.js");
15
15
  * @param {*} value - The default value to return if the property is not found
16
16
  * @returns {Object} The modified object
17
17
  */
18
- const dotSet = function (arrayObject, dotNotation) {
19
- var _arrayObject$key;
20
- let value = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
18
+ const dotSet = (arrayObject, dotNotation, value = null) => {
21
19
  let key = (0, _strBefore.strBefore)(dotNotation, '.');
22
20
  const lastKey = !key;
23
21
  if (lastKey) {
@@ -40,7 +38,7 @@ const dotSet = function (arrayObject, dotNotation) {
40
38
  arrayObject[dotNotation] = value;
41
39
  return arrayObject;
42
40
  }
43
- const next = (_arrayObject$key = arrayObject[key]) !== null && _arrayObject$key !== void 0 ? _arrayObject$key : [];
41
+ const next = arrayObject[key] ?? [];
44
42
  arrayObject[key] = dotSet(next, (0, _strAfter.strAfter)(dotNotation, '.'), value);
45
43
  return arrayObject;
46
44
  };
package/dist/watchTest.js CHANGED
@@ -1,7 +1,6 @@
1
1
  'use strict'
2
2
 
3
3
  require('core-js/modules/esnext.weak-map.delete-all.js')
4
- require('core-js/modules/web.dom-collections.iterator.js')
5
4
  Object.defineProperty(exports, '__esModule', {
6
5
  value: true
7
6
  })
@@ -1 +1 @@
1
- "use strict";require("core-js/modules/esnext.weak-map.delete-all.js"),require("core-js/modules/web.dom-collections.iterator.js"),Object.defineProperty(exports,"__esModule",{value:!0}),exports.watchTest=void 0;var gulpConfig=_interopRequireWildcard(require("../gulp.config.js")),_gulp=require("gulp"),_testQuick=require("./testQuick.js");function _interopRequireWildcard(e,t){if("function"==typeof WeakMap)var r=new WeakMap,i=new WeakMap;return(_interopRequireWildcard=function(e,t){if(!t&&e&&e.__esModule)return e;var o,u,n={__proto__:null,default:e};if(null===e||"object"!=typeof e&&"function"!=typeof e)return n;if(o=t?i:r){if(o.has(e))return o.get(e);o.set(e,n)}for(const t in e)"default"!==t&&{}.hasOwnProperty.call(e,t)&&((u=(o=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,t))&&(u.get||u.set)?o(n,t,u):n[t]=e[t]);return n})(e,t)}const watchTest=()=>(0,_gulp.watch)(gulpConfig.get("test.watch"),{ignoreInitial:!1},_testQuick.testQuick);exports.watchTest=watchTest;
1
+ "use strict";require("core-js/modules/esnext.weak-map.delete-all.js"),Object.defineProperty(exports,"__esModule",{value:!0}),exports.watchTest=void 0;var gulpConfig=_interopRequireWildcard(require("../gulp.config.js")),_gulp=require("gulp"),_testQuick=require("./testQuick.js");function _interopRequireWildcard(e,t){if("function"==typeof WeakMap)var r=new WeakMap,i=new WeakMap;return(_interopRequireWildcard=function(e,t){if(!t&&e&&e.__esModule)return e;var u,n,o={__proto__:null,default:e};if(null===e||"object"!=typeof e&&"function"!=typeof e)return o;if(u=t?i:r){if(u.has(e))return u.get(e);u.set(e,o)}for(const t in e)"default"!==t&&{}.hasOwnProperty.call(e,t)&&((n=(u=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,t))&&(n.get||n.set)?u(o,t,n):o[t]=e[t]);return o})(e,t)}const watchTest=()=>(0,_gulp.watch)(gulpConfig.get("test.watch"),{ignoreInitial:!1},_testQuick.testQuick);exports.watchTest=watchTest;
@@ -12,6 +12,30 @@ const genericFunction = () => Promise.resolve(true)
12
12
 
13
13
  jest.mock('./partials/clean.mjs', () => ({ clean: jest.fn(genericFunction) }))
14
14
  jest.mock('./testFull.mjs', () => ({ testFull: jest.fn(genericFunction) }))
15
+ // tsFor's real implementation loads gulp-ts-compile (a genuine ESM-only package) via a dynamic import() hidden
16
+ // from babel's static analysis - necessary for production correctness (see tsFor.mjs's own comments), but this
17
+ // project's current CommonJS-transform-based Jest setup can't execute a real dynamic import at all: it doesn't
18
+ // just fail cleanly, it segfaults the whole Jest worker. Replace the whole module here with a fake that does
19
+ // real (not mocked-away) TypeScript transpilation via `ts.transpileModule`, so the typescript.enabled tests
20
+ // below still exercise genuine compile behavior end to end - gulp-ts-compile's own test suite separately covers
21
+ // its whole-program/cross-file-import behavior.
22
+ jest.mock('./partials/tsFor.mjs', () => ({
23
+ tsFor: (srcPath, distPath) => (done) => {
24
+ const nodeFs = require('fs')
25
+ const nodePath = require('path')
26
+ const glob = require('glob')
27
+ const ts = require('typescript')
28
+ nodeFs.mkdirSync(distPath, { recursive: true })
29
+ for (const file of glob.globSync(srcPath)) {
30
+ const contents = nodeFs.readFileSync(file).toString()
31
+ const { outputText } = ts.transpileModule(contents, { compilerOptions: { declaration: true } })
32
+ const base = nodePath.basename(file).replace(/\.tsx?$/, '')
33
+ nodeFs.writeFileSync(`${distPath}/${base}.js`, outputText)
34
+ nodeFs.writeFileSync(`${distPath}/${base}.d.ts`, '')
35
+ }
36
+ done()
37
+ }
38
+ }))
15
39
 
16
40
  const file1Contents = '/**\n' +
17
41
  ' * Console log out a greeting with given input.\n' +
@@ -1,9 +1,39 @@
1
1
  import fs from 'fs'
2
+ import { Transform, PassThrough } from 'node:stream'
3
+ import ts from 'typescript'
4
+ import File from 'vinyl'
2
5
  import * as setUp from '../test-helpers/setUp.mjs'
3
6
  import { distFor } from './distFor.mjs'
4
7
  import { countMatches, fileExists } from 'test-filesystem'
5
8
  import { tsFor } from './tsFor.mjs'
6
9
 
10
+ // tsFor's real implementation loads gulp-ts-compile (a genuine ESM-only package) via a dynamic import() hidden
11
+ // from babel's static analysis - necessary for production correctness (see tsFor.mjs's own comments), but this
12
+ // project's current CommonJS-transform-based Jest setup cannot execute a real dynamic import at all: it doesn't
13
+ // just fail cleanly, it segfaults the whole Jest worker. This fake stands in for it here, doing real (not
14
+ // mocked-away) TypeScript transpilation via `ts.transpileModule` so this test still exercises genuine compile
15
+ // behavior - gulp-ts-compile's own test suite separately covers its whole-program/cross-file-import behavior.
16
+ const fakeLoadTsCompile = () => Promise.resolve((options) => {
17
+ const transform = new Transform({
18
+ objectMode: true,
19
+ transform (file, enc, callback) {
20
+ const { outputText } = ts.transpileModule(file.contents.toString(), { compilerOptions: options })
21
+ jsStream.push(new File({ cwd: file.cwd, base: file.base, path: file.path.replace(/\.tsx?$/, '.js'), contents: Buffer.from(outputText) }))
22
+ callback()
23
+ },
24
+ flush (callback) {
25
+ jsStream.end()
26
+ dtsStream.end()
27
+ callback()
28
+ }
29
+ })
30
+ const jsStream = new PassThrough({ objectMode: true })
31
+ const dtsStream = new PassThrough({ objectMode: true })
32
+ transform.js = jsStream
33
+ transform.dts = dtsStream
34
+ return transform
35
+ })
36
+
7
37
  setUp.setDefaults('test-dist-for')
8
38
  const gulpConfig = setUp.gulpConfig
9
39
 
@@ -86,7 +116,7 @@ describe('distFor', () => {
86
116
  const srcPath = gulpConfig.get('srcPath')
87
117
  const srcFile = `${srcPath}/distFor.js`
88
118
  fs.writeFileSync(srcFile, rawContents)
89
- expect.assertions(5)
119
+ expect.assertions(3)
90
120
  const oldContents = fs.readFileSync(srcFile).toString()
91
121
  expect(countMatches(oldContents, 'const ')).toEqual(7)
92
122
  const distPath = gulpConfig.get('dist.to')
@@ -94,14 +124,12 @@ describe('distFor', () => {
94
124
  .on('finish', () => {
95
125
  expect(fileExists(distPath)).toBeTruthy()
96
126
  const babelifiedContents = fs.readFileSync(`${distPath}/distFor.js`).toString()
97
- expect(countMatches(babelifiedContents, '"use strict"')).toEqual(1)
98
- /* There used to be a nice check here where `const` and `let` would be swapped to `var`, but that no longer
99
- happens.
100
- It would be nice if it still happened, but due to 'browserlist' supposedly, most browsers support
101
- `const` and `let` now.
127
+ /* There used to be checks here for `const`/`let` being swapped to `var`, and for arrow functions being
128
+ compiled down to `function`/`arguments`, but neither happens anymore now that 'browserslist' resolves to
129
+ targets that natively support this syntax - there's nothing stable left to count. What still matters -
130
+ that babel actually ran and produced a valid CommonJS module - is confirmed by the "use strict" check.
102
131
  */
103
- expect(countMatches(babelifiedContents, 'function')).toEqual(1)
104
- expect(countMatches(babelifiedContents, 'arguments')).toEqual(6)
132
+ expect(countMatches(babelifiedContents, '"use strict"')).toEqual(1)
105
133
  done()
106
134
  })
107
135
  .on('error', error => {
@@ -122,7 +150,7 @@ describe('distFor', () => {
122
150
  const distPath = gulpConfig.get('dist.to')
123
151
  const tsFrom = gulpConfig.get('typescript.from')
124
152
  const tsTo = gulpConfig.get('typescript.to')
125
- tsFor(tsFrom, tsTo)(() => {
153
+ tsFor(tsFrom, tsTo, fakeLoadTsCompile)(() => {
126
154
  distFor()
127
155
  .on('finish', () => {
128
156
  expect(fileExists(distPath)).toBeTruthy()
@@ -153,7 +181,10 @@ describe('distFor', () => {
153
181
  .on('finish', () => {
154
182
  expect(fileExists(distPath)).toBeTruthy()
155
183
  const babelifiedContents = fs.readFileSync(`${distPath}/distFor.js`).toString()
156
- expect(countMatches(babelifiedContents, '.js')).toEqual(4)
184
+ // A total '.js' substring count is too fragile - it drifts with whichever core-js polyfill modules babel
185
+ // happens to pull in. Check specifically for the thing this test is about: the .mjs import extension in
186
+ // the source (./distForSrc.mjs) got rewritten to .js in the compiled require path.
187
+ expect(countMatches(babelifiedContents, 'distForSrc.js')).toEqual(1)
157
188
  done()
158
189
  })
159
190
  .on('error', error => {