js-build-tools 5.0.0 → 5.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.
- package/babel.config.js +18 -1
- package/dist/partials/addToReadme.js +17 -17
- package/dist/partials/beginWatcher.js +12 -12
- package/dist/partials/clean.js +14 -14
- package/dist/partials/distFor.js +21 -21
- package/dist/partials/distForSrc.js +11 -11
- package/dist/partials/distSeries.js +19 -19
- package/dist/partials/minifyFor.js +16 -16
- package/dist/partials/readmeTemplate.js +14 -14
- package/dist/partials/runOnChange.js +28 -28
- package/dist/partials/sassFor.js +28 -28
- package/dist/partials/tsFor.js +89 -67
- package/dist/test-helpers/setUp.js +89 -89
- package/dist/utilities/dotGet.js +46 -46
- package/dist/utilities/dotNotate.js +46 -46
- package/dist/utilities/dotSet.js +37 -37
- package/dist/utilities/isObject.js +8 -8
- package/dist/utilities/strAfter.js +11 -11
- package/dist/utilities/strBefore.js +11 -11
- package/functions/partials/tsFor.mjs +25 -3
- package/functions/partials/tsFor.test.mjs +11 -1
- package/package.json +6 -2
package/dist/utilities/dotSet.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.dotSet = void 0;
|
|
7
|
-
var _isObject = require("./isObject.js");
|
|
8
|
-
var _strAfter = require("./strAfter.js");
|
|
9
|
-
var _strBefore = require("./strBefore.js");
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.dotSet = void 0;
|
|
7
|
+
var _isObject = require("./isObject.js");
|
|
8
|
+
var _strAfter = require("./strAfter.js");
|
|
9
|
+
var _strBefore = require("./strBefore.js");
|
|
10
10
|
/**
|
|
11
11
|
* Set a nested property value an object.
|
|
12
12
|
* Original source concepts from {@link https://github.com/jheagle/si-funciona/blob/main/src/helpers/objects/dotSet.ts Sí, funciona}
|
|
@@ -14,32 +14,32 @@ var _strBefore = require("./strBefore.js");
|
|
|
14
14
|
* @param {string} dotNotation - The path for the property
|
|
15
15
|
* @param {*} value - The default value to return if the property is not found
|
|
16
16
|
* @returns {Object} The modified object
|
|
17
|
-
*/
|
|
18
|
-
const dotSet = (arrayObject, dotNotation, value = null) => {
|
|
19
|
-
let key = (0, _strBefore.strBefore)(dotNotation, '.');
|
|
20
|
-
const lastKey = !key;
|
|
21
|
-
if (lastKey) {
|
|
22
|
-
key = dotNotation;
|
|
23
|
-
}
|
|
24
|
-
if (key === '*') {
|
|
25
|
-
for (let wildKey in arrayObject) {
|
|
26
|
-
if (lastKey) {
|
|
27
|
-
arrayObject[wildKey] = value;
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
if (!(0, _isObject.isObject)(arrayObject[wildKey])) {
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
dotSet(arrayObject[wildKey], (0, _strAfter.strAfter)(dotNotation, '.'), value);
|
|
34
|
-
}
|
|
35
|
-
return arrayObject;
|
|
36
|
-
}
|
|
37
|
-
if (lastKey) {
|
|
38
|
-
arrayObject[dotNotation] = value;
|
|
39
|
-
return arrayObject;
|
|
40
|
-
}
|
|
41
|
-
const next = arrayObject[key] ?? [];
|
|
42
|
-
arrayObject[key] = dotSet(next, (0, _strAfter.strAfter)(dotNotation, '.'), value);
|
|
43
|
-
return arrayObject;
|
|
44
|
-
};
|
|
17
|
+
*/
|
|
18
|
+
const dotSet = (arrayObject, dotNotation, value = null) => {
|
|
19
|
+
let key = (0, _strBefore.strBefore)(dotNotation, '.');
|
|
20
|
+
const lastKey = !key;
|
|
21
|
+
if (lastKey) {
|
|
22
|
+
key = dotNotation;
|
|
23
|
+
}
|
|
24
|
+
if (key === '*') {
|
|
25
|
+
for (let wildKey in arrayObject) {
|
|
26
|
+
if (lastKey) {
|
|
27
|
+
arrayObject[wildKey] = value;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (!(0, _isObject.isObject)(arrayObject[wildKey])) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
dotSet(arrayObject[wildKey], (0, _strAfter.strAfter)(dotNotation, '.'), value);
|
|
34
|
+
}
|
|
35
|
+
return arrayObject;
|
|
36
|
+
}
|
|
37
|
+
if (lastKey) {
|
|
38
|
+
arrayObject[dotNotation] = value;
|
|
39
|
+
return arrayObject;
|
|
40
|
+
}
|
|
41
|
+
const next = arrayObject[key] ?? [];
|
|
42
|
+
arrayObject[key] = dotSet(next, (0, _strAfter.strAfter)(dotNotation, '.'), value);
|
|
43
|
+
return arrayObject;
|
|
44
|
+
};
|
|
45
45
|
exports.dotSet = dotSet;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.isObject = void 0;
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isObject = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* Check if the provided thing is an object / array.
|
|
9
9
|
* Original source concepts from {@link https://github.com/jheagle/si-funciona/blob/main/src/helpers/objects/isObject.ts Sí, funciona}
|
|
10
10
|
* @param {*} object
|
|
11
11
|
* @returns {boolean}
|
|
12
|
-
*/
|
|
13
|
-
const isObject = object => typeof object === 'object' && object !== null;
|
|
12
|
+
*/
|
|
13
|
+
const isObject = object => typeof object === 'object' && object !== null;
|
|
14
14
|
exports.isObject = isObject;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.strAfter = void 0;
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.strAfter = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* Retrieve the string part after the search match.
|
|
9
9
|
* Original source from {@link https://github.com/jheagle/si-funciona/blob/main/src/helpers/strings/strAfter.ts Sí, funciona}
|
|
10
10
|
* @param {string} str
|
|
11
11
|
* @param {string} search
|
|
12
12
|
* @returns {string}
|
|
13
|
-
*/
|
|
14
|
-
const strAfter = (str, search) => {
|
|
15
|
-
const index = str.indexOf(search);
|
|
16
|
-
return index === -1 ? '' : str.substring(index + search.length);
|
|
17
|
-
};
|
|
13
|
+
*/
|
|
14
|
+
const strAfter = (str, search) => {
|
|
15
|
+
const index = str.indexOf(search);
|
|
16
|
+
return index === -1 ? '' : str.substring(index + search.length);
|
|
17
|
+
};
|
|
18
18
|
exports.strAfter = strAfter;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.strBefore = void 0;
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.strBefore = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* Retrieve the string part before the search match.
|
|
9
9
|
* Original source from {@link https://github.com/jheagle/si-funciona/blob/main/src/helpers/strings/strBefore.ts Sí, funciona}
|
|
10
10
|
* @param {string} str
|
|
11
11
|
* @param {string} search
|
|
12
12
|
* @returns {string}
|
|
13
|
-
*/
|
|
14
|
-
const strBefore = (str, search) => {
|
|
15
|
-
const index = str.indexOf(search);
|
|
16
|
-
return index === -1 ? '' : str.slice(0, index);
|
|
17
|
-
};
|
|
13
|
+
*/
|
|
14
|
+
const strBefore = (str, search) => {
|
|
15
|
+
const index = str.indexOf(search);
|
|
16
|
+
return index === -1 ? '' : str.slice(0, index);
|
|
17
|
+
};
|
|
18
18
|
exports.strBefore = strBefore;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { dest, src } from 'gulp'
|
|
2
2
|
import path from 'node:path'
|
|
3
3
|
import * as gulpConfig from '../../gulp.config.mjs'
|
|
4
|
-
import
|
|
4
|
+
import { createRequire } from 'node:module'
|
|
5
5
|
|
|
6
6
|
// gulp-ts-compile ships ESM-only (no CJS build - see its own package.json) since it's meant to be consumed by
|
|
7
7
|
// gulpfiles running under a real ESM loader, same as this project's own gulpfile.mjs does. This project also
|
|
@@ -19,6 +19,27 @@ const importGulpTsCompile = new Function('return import(\'gulp-ts-compile\')')
|
|
|
19
19
|
* @param {import('node:stream').Stream} stream
|
|
20
20
|
* @returns {Promise<void>}
|
|
21
21
|
*/
|
|
22
|
+
const installHint = 'Install it in your project with: npm install --save-dev typescript'
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Load the project's own copy of TypeScript (an optional peer dependency, only needed when the typescript task is
|
|
26
|
+
* enabled) from the project being built, so projects which do not use TypeScript never need it installed.
|
|
27
|
+
* @memberOf module:partials
|
|
28
|
+
* @param {string} [projectPath=process.cwd()] The folder of the project (which has the package.json) being built.
|
|
29
|
+
* @returns {Object} The TypeScript compiler API module.
|
|
30
|
+
* @throws {Error} With install instructions when typescript is not installed.
|
|
31
|
+
*/
|
|
32
|
+
export const loadTypescript = (projectPath = process.cwd()) => {
|
|
33
|
+
try {
|
|
34
|
+
return createRequire(path.join(projectPath, 'package.json'))('typescript')
|
|
35
|
+
} catch (error) {
|
|
36
|
+
if (error.code === 'MODULE_NOT_FOUND' && /Cannot find module 'typescript'/.test(error.message)) {
|
|
37
|
+
throw new Error(`The typescript task needs the optional peer dependency typescript, which is not installed. ${installHint}`)
|
|
38
|
+
}
|
|
39
|
+
throw error
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
22
43
|
const streamToPromise = (stream) => new Promise((resolve, reject) => {
|
|
23
44
|
stream.on('finish', resolve)
|
|
24
45
|
stream.on('error', reject)
|
|
@@ -33,7 +54,7 @@ const streamToPromise = (stream) => new Promise((resolve, reject) => {
|
|
|
33
54
|
* @param {string} configPath - Path to a tsconfig.json file.
|
|
34
55
|
* @returns {import('typescript').CompilerOptions}
|
|
35
56
|
*/
|
|
36
|
-
const readCompilerOptions = (configPath) => {
|
|
57
|
+
const readCompilerOptions = (ts, configPath) => {
|
|
37
58
|
const configFile = ts.readConfigFile(configPath, ts.sys.readFile)
|
|
38
59
|
const parsedConfig = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(configPath))
|
|
39
60
|
return parsedConfig.options
|
|
@@ -60,6 +81,7 @@ export const tsFor = (
|
|
|
60
81
|
if (gulpConfig.get('typescript.enabled') === false) {
|
|
61
82
|
return () => {}
|
|
62
83
|
}
|
|
84
|
+
const ts = loadTypescript()
|
|
63
85
|
const configPath = gulpConfig.get('typescript.config')
|
|
64
86
|
// When no tsconfig.json is configured, target/module are pinned explicitly rather than left for TypeScript's
|
|
65
87
|
// own compiler defaults - those defaults have already shifted once across a TypeScript version bump in this
|
|
@@ -67,7 +89,7 @@ export const tsFor = (
|
|
|
67
89
|
// pinning them keeps this task's output stable across future TypeScript upgrades too. ES5/CommonJS matches
|
|
68
90
|
// what the downstream babel/browserify bundling pipeline has always assumed it receives.
|
|
69
91
|
const compilerOptions = configPath
|
|
70
|
-
? readCompilerOptions(configPath)
|
|
92
|
+
? readCompilerOptions(ts, configPath)
|
|
71
93
|
: { declaration: true, target: ts.ScriptTarget.ES5, module: ts.ModuleKind.CommonJS, esModuleInterop: false }
|
|
72
94
|
// Accepts gulp's own callback-style task convention (an optional `done`, called once finished) rather than
|
|
73
95
|
// just returning a Promise, since callers may invoke the returned function directly with a callback instead
|
|
@@ -3,7 +3,7 @@ import { Transform, PassThrough } from 'node:stream'
|
|
|
3
3
|
import ts from 'typescript'
|
|
4
4
|
import File from 'vinyl'
|
|
5
5
|
import * as setUp from '../test-helpers/setUp.mjs'
|
|
6
|
-
import { tsFor } from './tsFor.mjs'
|
|
6
|
+
import { tsFor, loadTypescript } from './tsFor.mjs'
|
|
7
7
|
import { countMatches } from 'test-filesystem'
|
|
8
8
|
|
|
9
9
|
setUp.setDefaults('test-ts-for')
|
|
@@ -75,3 +75,13 @@ describe('tsFor', () => {
|
|
|
75
75
|
expect(result).toBeInstanceOf(Function)
|
|
76
76
|
})
|
|
77
77
|
})
|
|
78
|
+
|
|
79
|
+
describe('loadTypescript', () => {
|
|
80
|
+
test('loads the typescript of the project being built', () => {
|
|
81
|
+
expect(loadTypescript().version).toBe(ts.version)
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
test('explains how to install typescript when the project does not have it', () => {
|
|
85
|
+
expect(() => loadTypescript('/')).toThrow(/optional peer dependency typescript.*npm install --save-dev typescript/)
|
|
86
|
+
})
|
|
87
|
+
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "js-build-tools",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.1.1",
|
|
4
4
|
"description": "Standardised build process with gulp.",
|
|
5
5
|
"main": "gulpfile.base.js",
|
|
6
6
|
"exports": {
|
|
@@ -77,11 +77,15 @@
|
|
|
77
77
|
"vinyl-source-stream": "^2.0.0"
|
|
78
78
|
},
|
|
79
79
|
"peerDependencies": {
|
|
80
|
-
"gulp-imagemin": ">=9.0.0"
|
|
80
|
+
"gulp-imagemin": ">=9.0.0",
|
|
81
|
+
"typescript": ">=5.0.0 <7.0.0"
|
|
81
82
|
},
|
|
82
83
|
"peerDependenciesMeta": {
|
|
83
84
|
"gulp-imagemin": {
|
|
84
85
|
"optional": true
|
|
86
|
+
},
|
|
87
|
+
"typescript": {
|
|
88
|
+
"optional": true
|
|
85
89
|
}
|
|
86
90
|
},
|
|
87
91
|
"files": [
|