js-build-tools 4.0.12 → 4.1.0
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/README.md +0 -120
- package/dist/build.js +1 -3
- package/dist/build.min.js +1 -1
- package/dist/bundle.js +1 -2
- package/dist/bundle.min.js +1 -1
- package/dist/bundleLint.js +1 -2
- package/dist/bundleLint.min.js +1 -1
- package/dist/bundleMinify.js +1 -2
- package/dist/bundleMinify.min.js +1 -1
- package/dist/copyFonts.js +0 -1
- package/dist/copyFonts.min.js +1 -1
- package/dist/default.js +1 -5
- package/dist/default.min.js +1 -1
- package/dist/distLint.js +0 -1
- package/dist/distLint.min.js +1 -1
- package/dist/distMinify.js +0 -1
- package/dist/distMinify.min.js +1 -1
- package/dist/partials/addToReadme.js +0 -1
- package/dist/partials/beginWatcher.js +0 -1
- package/dist/partials/clean.js +0 -1
- package/dist/partials/distFor.js +6 -14
- package/dist/partials/distForSrc.js +1 -5
- package/dist/partials/distSeries.js +1 -5
- package/dist/partials/imagesFor.js +7 -12
- package/dist/partials/readmeTemplate.js +0 -1
- package/dist/partials/runOnChange.js +3 -7
- package/dist/partials/sassFor.js +4 -9
- package/dist/partials/tsFor.js +78 -27
- package/dist/test-helpers/setUp.js +20 -22
- package/dist/testFull.js +0 -1
- package/dist/testFull.min.js +1 -1
- package/dist/testHelpers.js +0 -1
- package/dist/testHelpers.min.js +1 -1
- package/dist/testQuick.js +0 -1
- package/dist/testQuick.min.js +1 -1
- package/dist/utilities/dotGet.js +2 -6
- package/dist/utilities/dotNotate.js +6 -15
- package/dist/utilities/dotSet.js +2 -4
- package/dist/watchTest.js +0 -1
- package/dist/watchTest.min.js +1 -1
- package/functions/build.test.mjs +24 -0
- package/functions/partials/distFor.test.mjs +41 -10
- package/functions/partials/tsFor.mjs +66 -9
- package/functions/partials/tsFor.test.mjs +31 -1
- package/package.json +8 -6
package/dist/partials/tsFor.js
CHANGED
|
@@ -1,34 +1,85 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
require("core-js/modules/esnext.weak-map.delete-all.js");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
|
|
11
|
-
var
|
|
12
|
-
function
|
|
13
|
-
function
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
+
const compilerOptions = configPath ? readCompilerOptions(configPath) : {
|
|
71
|
+
declaration: true
|
|
72
|
+
};
|
|
73
|
+
// Accepts gulp's own callback-style task convention (an optional `done`, called once finished) rather than
|
|
74
|
+
// just returning a Promise, since callers may invoke the returned function directly with a callback instead
|
|
75
|
+
// of relying on gulp's own runner to observe a returned Promise.
|
|
76
|
+
return done => {
|
|
77
|
+
const compile = async () => {
|
|
78
|
+
const tsCompile = await loadTsCompile();
|
|
79
|
+
const tsResult = (0, _gulp.src)(srcPath).pipe(tsCompile(compilerOptions));
|
|
80
|
+
await Promise.all([streamToPromise(tsResult.dts.pipe((0, _gulp.dest)(distPath))), streamToPromise(tsResult.js.pipe((0, _gulp.dest)(distPath)))]);
|
|
81
|
+
};
|
|
82
|
+
return typeof done === 'function' ? compile().then(() => done(), done) : compile();
|
|
83
|
+
};
|
|
84
|
+
};
|
|
34
85
|
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 =
|
|
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 =
|
|
67
|
-
|
|
68
|
-
|
|
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 =
|
|
72
|
-
const browserPath =
|
|
73
|
-
const sassPath =
|
|
74
|
-
gulpConfig.set('browser.from',
|
|
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',
|
|
78
|
-
gulpConfig.set('dist.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',
|
|
81
|
-
gulpConfig.set('fonts.to',
|
|
82
|
-
gulpConfig.set('images.from',
|
|
83
|
-
gulpConfig.set('images.to',
|
|
84
|
-
gulpConfig.set('readme.template',
|
|
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',
|
|
84
|
+
gulpConfig.set('readme.from', `${srcPath}/**/!(*.test).js`);
|
|
87
85
|
gulpConfig.set('rootPath', tempDir);
|
|
88
|
-
gulpConfig.set('sass.from',
|
|
86
|
+
gulpConfig.set('sass.from', `${sassPath}/**/*.+(scss|sass)`);
|
|
89
87
|
gulpConfig.set('sass.path', sassPath);
|
|
90
|
-
gulpConfig.set('sass.to',
|
|
88
|
+
gulpConfig.set('sass.to', `${browserPath}/css`);
|
|
91
89
|
gulpConfig.set('srcPath', srcPath);
|
|
92
|
-
gulpConfig.set('typescript.from',
|
|
90
|
+
gulpConfig.set('typescript.from', `${srcPath}/**/*.ts`);
|
|
93
91
|
gulpConfig.set('typescript.to', distPath);
|
|
94
|
-
gulpConfig.set('test.watch',
|
|
92
|
+
gulpConfig.set('test.watch', `${srcPath}/**/*.js`);
|
|
95
93
|
};
|
|
96
94
|
exports.setDefaults = setDefaults;
|
package/dist/testFull.js
CHANGED
package/dist/testFull.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";require("core-js/modules/esnext.weak-map.delete-all.js"),
|
|
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=_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 n,o,i={__proto__:null,default:e};if(null===e||"object"!=typeof e&&"function"!=typeof e)return i;if(n=t?u:r){if(n.has(e))return n.get(e);n.set(e,i)}for(const t in e)"default"!==t&&{}.hasOwnProperty.call(e,t)&&((o=(n=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,t))&&(o.get||o.set)?n(i,t,o):i[t]=e[t]);return i})(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;
|
package/dist/testHelpers.js
CHANGED
package/dist/testHelpers.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";require("core-js/modules/esnext.weak-map.delete-all.js"),
|
|
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
package/dist/testQuick.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";require("core-js/modules/esnext.weak-map.delete-all.js"),
|
|
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=_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,n,o={__proto__:null,default:e};if(null===e||"object"!=typeof e&&"function"!=typeof e)return o;if(i=t?u:r){if(i.has(e))return i.get(e);i.set(e,o)}for(const t in e)"default"!==t&&{}.hasOwnProperty.call(e,t)&&((n=(i=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,t))&&(n.get||n.set)?i(o,t,n):o[t]=e[t]);return o})(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;
|
package/dist/utilities/dotGet.js
CHANGED
|
@@ -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 =
|
|
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
|
-
|
|
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 =
|
|
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(
|
|
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 =
|
|
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 =
|
|
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,
|
|
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 =
|
|
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;
|
package/dist/utilities/dotSet.js
CHANGED
|
@@ -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 =
|
|
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 =
|
|
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
package/dist/watchTest.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";require("core-js/modules/esnext.weak-map.delete-all.js"),
|
|
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;
|
package/functions/build.test.mjs
CHANGED
|
@@ -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(
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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, '
|
|
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
|
-
|
|
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 => {
|
|
@@ -1,22 +1,79 @@
|
|
|
1
|
-
import { dest,
|
|
1
|
+
import { dest, src } from 'gulp'
|
|
2
|
+
import path from 'node:path'
|
|
2
3
|
import * as gulpConfig from '../../gulp.config.mjs'
|
|
3
|
-
import ts from '
|
|
4
|
+
import ts from 'typescript'
|
|
5
|
+
|
|
6
|
+
// gulp-ts-compile ships ESM-only (no CJS build - see its own package.json) since it's meant to be consumed by
|
|
7
|
+
// gulpfiles running under a real ESM loader, same as this project's own gulpfile.mjs does. This project also
|
|
8
|
+
// compiles itself to a CommonJS build (dist/*.js, this file's own compiled counterpart) for consumers using
|
|
9
|
+
// require() though, and even a dynamic `import()` gets downleveled by babel's CommonJS transform into a
|
|
10
|
+
// require() call - which can't load a real ES module. Hiding the import() call inside a Function constructor is
|
|
11
|
+
// the standard escape hatch: babel can't see (and so can't rewrite) an import expression that only exists as a
|
|
12
|
+
// runtime-evaluated string, so it survives as a genuine dynamic import, capable of loading gulp-ts-compile from
|
|
13
|
+
// either build.
|
|
14
|
+
const importGulpTsCompile = new Function('return import(\'gulp-ts-compile\')')
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Wrap a stream in a promise that resolves once it finishes writing.
|
|
18
|
+
* @memberOf module:partials
|
|
19
|
+
* @param {import('node:stream').Stream} stream
|
|
20
|
+
* @returns {Promise<void>}
|
|
21
|
+
*/
|
|
22
|
+
const streamToPromise = (stream) => new Promise((resolve, reject) => {
|
|
23
|
+
stream.on('finish', resolve)
|
|
24
|
+
stream.on('error', reject)
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Read a tsconfig.json file into real typescript.CompilerOptions values, using only TypeScript's stable, current,
|
|
29
|
+
* public config-reading API (the same one `tsc --project` itself uses internally) - never
|
|
30
|
+
* `ts.convertCompilerOptionsFromJson`, which is exactly the kind of internal/legacy surface that broke
|
|
31
|
+
* gulp-typescript when a removed API call started throwing under TypeScript 7.
|
|
32
|
+
* @memberOf module:partials
|
|
33
|
+
* @param {string} configPath - Path to a tsconfig.json file.
|
|
34
|
+
* @returns {import('typescript').CompilerOptions}
|
|
35
|
+
*/
|
|
36
|
+
const readCompilerOptions = (configPath) => {
|
|
37
|
+
const configFile = ts.readConfigFile(configPath, ts.sys.readFile)
|
|
38
|
+
const parsedConfig = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(configPath))
|
|
39
|
+
return parsedConfig.options
|
|
40
|
+
}
|
|
4
41
|
|
|
5
42
|
/**
|
|
6
43
|
* Starting at the source directory, find all the ts files and convert them into the distribution directory.
|
|
7
44
|
* @memberOf module:partials
|
|
8
45
|
* @param {string|array} [srcPath='']
|
|
9
46
|
* @param {string} [distPath='']
|
|
47
|
+
* @param {function(): Promise<Function>} [loadTsCompile] - Resolves the `gulp-ts-compile` default export. Real
|
|
48
|
+
* callers should never need to pass this - it exists so tests can inject a stand-in compiler, sidestepping the
|
|
49
|
+
* genuine dynamic `import()` above that this project's current CommonJS-transform-based Jest setup cannot
|
|
50
|
+
* execute without a broader (and riskier) migration to Jest's native ESM support. gulp-ts-compile's own test
|
|
51
|
+
* suite already covers real TypeScript-compile correctness - this function's own tests only need to verify its
|
|
52
|
+
* config resolution and stream wiring.
|
|
10
53
|
* @returns {Function}
|
|
11
|
-
* @see `https://www.typescriptlang.org/docs/handbook/gulp.html` for more info
|
|
12
54
|
*/
|
|
13
|
-
export const tsFor = (
|
|
55
|
+
export const tsFor = (
|
|
56
|
+
srcPath = gulpConfig.get('typescript.from'),
|
|
57
|
+
distPath = gulpConfig.get('typescript.to'),
|
|
58
|
+
loadTsCompile = () => importGulpTsCompile().then(({ default: tsCompile }) => tsCompile)
|
|
59
|
+
) => {
|
|
14
60
|
if (gulpConfig.get('typescript.enabled') === false) {
|
|
15
61
|
return () => {}
|
|
16
62
|
}
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
63
|
+
const configPath = gulpConfig.get('typescript.config')
|
|
64
|
+
const compilerOptions = configPath ? readCompilerOptions(configPath) : { declaration: true }
|
|
65
|
+
// Accepts gulp's own callback-style task convention (an optional `done`, called once finished) rather than
|
|
66
|
+
// just returning a Promise, since callers may invoke the returned function directly with a callback instead
|
|
67
|
+
// of relying on gulp's own runner to observe a returned Promise.
|
|
68
|
+
return (done) => {
|
|
69
|
+
const compile = async () => {
|
|
70
|
+
const tsCompile = await loadTsCompile()
|
|
71
|
+
const tsResult = src(srcPath).pipe(tsCompile(compilerOptions))
|
|
72
|
+
await Promise.all([
|
|
73
|
+
streamToPromise(tsResult.dts.pipe(dest(distPath))),
|
|
74
|
+
streamToPromise(tsResult.js.pipe(dest(distPath)))
|
|
75
|
+
])
|
|
76
|
+
}
|
|
77
|
+
return typeof done === 'function' ? compile().then(() => done(), done) : compile()
|
|
78
|
+
}
|
|
22
79
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
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 { tsFor } from './tsFor.mjs'
|
|
4
7
|
import { countMatches } from 'test-filesystem'
|
|
@@ -10,6 +13,33 @@ const rawContents = 'export function sayHello(name: string) {\n' +
|
|
|
10
13
|
' return `Hello from ${name}`;\n' +
|
|
11
14
|
'}'
|
|
12
15
|
|
|
16
|
+
// tsFor's real implementation loads gulp-ts-compile (a genuine ESM-only package) via a dynamic import() hidden
|
|
17
|
+
// from babel's static analysis - necessary for production correctness (see tsFor.mjs's own comments), but not
|
|
18
|
+
// something this project's current CommonJS-transform-based Jest setup can execute without a much bigger
|
|
19
|
+
// migration to Jest's native ESM support. This fake stands in for it here, doing real (not mocked-away)
|
|
20
|
+
// TypeScript transpilation via `ts.transpileModule` so this test still exercises genuine compile behavior -
|
|
21
|
+
// gulp-ts-compile's own test suite separately covers its whole-program/cross-file-import compile behavior.
|
|
22
|
+
const fakeLoadTsCompile = () => Promise.resolve((options) => {
|
|
23
|
+
const transform = new Transform({
|
|
24
|
+
objectMode: true,
|
|
25
|
+
transform (file, enc, callback) {
|
|
26
|
+
const { outputText } = ts.transpileModule(file.contents.toString(), { compilerOptions: options })
|
|
27
|
+
jsStream.push(new File({ cwd: file.cwd, base: file.base, path: file.path.replace(/\.ts$/, '.js'), contents: Buffer.from(outputText) }))
|
|
28
|
+
callback()
|
|
29
|
+
},
|
|
30
|
+
flush (callback) {
|
|
31
|
+
jsStream.end()
|
|
32
|
+
dtsStream.end()
|
|
33
|
+
callback()
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
const jsStream = new PassThrough({ objectMode: true })
|
|
37
|
+
const dtsStream = new PassThrough({ objectMode: true })
|
|
38
|
+
transform.js = jsStream
|
|
39
|
+
transform.dts = dtsStream
|
|
40
|
+
return transform
|
|
41
|
+
})
|
|
42
|
+
|
|
13
43
|
beforeEach(
|
|
14
44
|
() => setUp.beforeEach()
|
|
15
45
|
.then(
|
|
@@ -31,7 +61,7 @@ describe('tsFor', () => {
|
|
|
31
61
|
expect.assertions(3)
|
|
32
62
|
const oldContents = fs.readFileSync(srcFile).toString()
|
|
33
63
|
expect(countMatches(oldContents, 'sayHello(name: string)')).toEqual(1)
|
|
34
|
-
tsFor(srcFile, distPath)(() => {
|
|
64
|
+
tsFor(srcFile, distPath, fakeLoadTsCompile)(() => {
|
|
35
65
|
expect(fs.existsSync(distPath)).toBeTruthy()
|
|
36
66
|
const compiledContents = fs.readFileSync(`${distPath}/typeScript.js`).toString()
|
|
37
67
|
expect(countMatches(compiledContents, 'sayHello(name)')).toEqual(1)
|