Skip to content

Commit

Permalink
refactor: update and simplify some dependencies
Browse files Browse the repository at this point in the history
Since we can't adopt the latest versions of execa and globby due to ESM,
and we use them for very specific purposes here, replace them with
built-ins where possible (and use fast-glob where not possible).
  • Loading branch information
dpogue committed Oct 25, 2024
1 parent d77f379 commit 621c944
Show file tree
Hide file tree
Showing 10 changed files with 1,172 additions and 688 deletions.
12 changes: 6 additions & 6 deletions build-tools/build-id.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@
* under the License.
*/

const fs = require('fs');
const path = require('path');
const execa = require('execa');
const fs = require('node:fs');
const path = require('node:path');
const child_process = require('node:child_process');
const { pkgRoot } = require('./common');

async function getBuildId () {
function getBuildId () {
// Use git describe if in cordova-js repo, else use package version
return fs.existsSync(path.join(pkgRoot, '.git'))
? describeGitRepo()
: require('../package').version;
}

async function describeGitRepo () {
function describeGitRepo () {
const gitArgs = ['describe', '--always', '--tags', '--match=rel/*', '--dirty'];
return (await execa('git', gitArgs, { cwd: pkgRoot })).stdout;
return child_process.spawnSync('git', gitArgs, { cwd: pkgRoot }).stdout;
}

module.exports = getBuildId;
2 changes: 1 addition & 1 deletion build-tools/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

const path = require('path');
const path = require('node:path');
const bundle = require('./bundle');
const scripts = require('./scripts');
const modules = require('./modules');
Expand Down
9 changes: 4 additions & 5 deletions build-tools/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
* under the License.
*/

const { resolve } = require('path');
const { promisify } = require('util');
const { pipeline, Readable } = require('stream');
const { resolve } = require('node:path');
const { pipeline } = require('node:stream/promises');
const { build } = require('.');

const USAGE = `
Expand All @@ -47,8 +46,8 @@ const commands = {
async build (args) {
const platformRoot = resolve(args[0] || process.cwd());
const bundleCode = await build({ platformRoot });
return promisify(pipeline)(
Readable.from([bundleCode]),
return pipeline(
[bundleCode],
process.stdout
);
}
Expand Down
18 changes: 13 additions & 5 deletions build-tools/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,20 @@
* under the License.
*/

const fs = require('node:fs/promises');
const path = require('path');
const globby = require('globby');
const fs = require('node:fs');
const path = require('node:path');

const pkgRoot = path.join(__dirname, '..');

function glob (pattern, opts) {
if (fs.globSync) {
return fs.globSync(pattern, opts);
} else {
const fastGlob = require('fast-glob');
return fastGlob.sync(pattern, opts);
}
}

module.exports = {
pkgRoot,

Expand All @@ -31,7 +39,7 @@ module.exports = {
},

readContents (f) {
return fs.readFile(f.path, 'utf8')
return fs.promises.readFile(f.path, 'utf8')
.then(contents => Object.assign({}, f, { contents }));
},

Expand All @@ -53,7 +61,7 @@ module.exports = {
},

collectModules (dir) {
return globby.sync(['**/*.js'], { cwd: dir })
return glob(['**/*.js'], { cwd: dir })
.map(fileName => ({
path: path.join(dir, fileName),
moduleId: fileName.slice(0, -3)
Expand Down
2 changes: 1 addition & 1 deletion build-tools/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

const path = require('path');
const path = require('node:path');

const {
readContents,
Expand Down
2 changes: 1 addition & 1 deletion build-tools/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

const path = require('path');
const path = require('node:path');
const {
readContents,
stripLicenseHeader,
Expand Down
2 changes: 1 addition & 1 deletion build-tools/test-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

const fs = require('node:fs');
const fsp = require('node:fs/promises');
const path = require('path');
const path = require('node:path');
const { build, collectModules } = require('.');

// istanbul-lib-instrument is provided by karma-coverage
Expand Down
Loading

0 comments on commit 621c944

Please sign in to comment.