Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update and simplify some dependencies #281

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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