Skip to content

Commit

Permalink
refactor: replace globby with tinyglobby (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperchupuDev authored Oct 16, 2024
1 parent c726221 commit 99a2632
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 39 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@ use of `package.json` configuration.

### Scripts

`scripts` is a [glob](https://github.com/sindresorhus/globby)
`scripts` is a [glob](https://github.com/SuperchupuDev/tinyglobby)
or list of globs. Files specified as `scripts` will be compiled
using `v8::ScriptCompiler` and placed into executable without
sources. They must conform to the JS standards of those Node.js versions
you target (see [Targets](#targets)), i.e. be already transpiled.

### Assets

`assets` is a [glob](https://github.com/sindresorhus/globby)
`assets` is a [glob](https://github.com/SuperchupuDev/tinyglobby)
or list of globs. Files specified as `assets` will be packaged
into executable as raw content without modifications. Javascript
files may also be specified as `assets`. Their sources will
Expand Down
4 changes: 2 additions & 2 deletions lib/walker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import assert from 'assert';
import fs from 'fs/promises';
import globby from 'globby';
import path from 'path';
import { builtinModules } from 'module';
import picomatch from 'picomatch';
import { globSync } from 'tinyglobby';

import {
ALIAS_AS_RELATIVE,
Expand Down Expand Up @@ -194,7 +194,7 @@ function upon(p: string, base: string) {
}

function collect(ps: string[]) {
return globby.sync(ps, { dot: true });
return globSync(ps, { absolute: true, dot: true });
}

function expandFiles(efs: string | string[], base: string) {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
"@babel/parser": "7.23.0",
"@babel/types": "7.23.0",
"@yao-pkg/pkg-fetch": "3.5.13",
"globby": "^11.1.0",
"into-stream": "^6.0.0",
"minimist": "^1.2.6",
"multistream": "^4.1.0",
"picomatch": "^4.0.2",
"picocolors": "^1.1.0",
"prebuild-install": "7.1.1",
"resolve": "^1.22.0",
"stream-meter": "^1.0.4"
"stream-meter": "^1.0.4",
"tinyglobby": "^0.2.9"
},
"devDependencies": {
"@babel/core": "7.23.0",
Expand Down
37 changes: 15 additions & 22 deletions test/test-79-npm/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const UPM = process.env.USE_PREINSTALLED_MODULES || false; // USE_PREINSTALLED_M
const fs = require('fs');
const path = require('path');
const assert = require('assert');
const globby = require('globby');
const { globSync } = require('tinyglobby');
const utils = require('../utils.js');

assert(!module.parent);
Expand Down Expand Up @@ -126,19 +126,12 @@ if (!UPM) {
})();

// note to developpers:
// you can set the env variable FILTER to something like "better-sqlite3/*.js"
// you can set the env variable FILTER to something like "better-sqlite3/*.js"
// to restrict this test to this single test case
const inputs = globby
.sync([
process.env.FILTER || './*/*.js',
'!./*/*.config.js',
'!./*/*.meta.js',
'!./*/gulpfile.js',
'!./*/*fixture*',
])
.map(function (result) {
return path.resolve(result);
});
const inputs = globSync([process.env.FILTER || '*/*.js'], {
absolute: true,
ignore: ['*/*.config.js', '*/*.meta.js', '*/gulpfile.js', '*/*fixture*'],
}).map((p) => path.normalize(p));

let times = {};
const ci = process.env.CI;
Expand Down Expand Up @@ -308,14 +301,14 @@ inputs.some(function (input) {
const deployFiles = [];

if (!meta.deployFiles && !meta.deployFilesFrom) {
globby
.sync(path.join(foldy, 'node_modules', '**', '*.node'))
.some(function (deployFrom) {
globSync(path.join(foldy, 'node_modules', '**', '*.node')).some(
function (deployFrom) {
deployFiles.push([
deployFrom,
path.join(path.dirname(output), path.basename(deployFrom)),
]);
});
},
);
}

const deployFilesRelative = [];
Expand Down Expand Up @@ -361,9 +354,8 @@ inputs.some(function (input) {
if (statFrom.isFile()) {
deployFiles.push([deployFrom, deployTo]);
} else {
globby
.sync(path.join(deployFrom, '**', '*'))
.some(function (deployFrom2) {
globSync(path.join(deployFrom, '**', '*')).some(
function (deployFrom2) {
const r = path.relative(deployFrom, deployFrom2);
const deployTo2 = path.join(deployTo, r);
if (fs.existsSync(deployFrom2)) {
Expand All @@ -372,7 +364,8 @@ inputs.some(function (input) {
deployFiles.push([deployFrom2, deployTo2]);
}
}
});
},
);
}
}
});
Expand Down Expand Up @@ -410,7 +403,7 @@ inputs.some(function (input) {
}
}

const rubbishes = globby.sync(path.join(path.dirname(output), '**', '*'));
const rubbishes = globSync(path.join(path.dirname(output), '**', '*'));

rubbishes.some(function (rubbish) {
utils.vacuum.sync(rubbish);
Expand Down
13 changes: 7 additions & 6 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

'use strict';

const globby = require('globby');
const path = require('path');
const pc = require('picocolors');
const { globSync } = require('tinyglobby');
const utils = require('./utils.js');
const host = 'node' + process.version.match(/^v(\d+)/)[1];
let target = process.argv[2] || 'host';
Expand Down Expand Up @@ -47,6 +47,7 @@ function joinAndForward(d) {
}

const list = [];
const ignore = [];

if (flavor.match(/^test/)) {
list.push(joinAndForward(`${flavor}/main.js`));
Expand All @@ -55,14 +56,14 @@ if (flavor.match(/^test/)) {
} else {
list.push(joinAndForward('**/main.js'));
if (flavor === 'no-npm') {
list.push('!' + joinAndForward('test-42-fetch-all'));
list.push('!' + joinAndForward('test-46-multi-arch'));
list.push('!' + joinAndForward('test-46-multi-arch-2'));
list.push('!' + joinAndForward('test-79-npm'));
ignore.push(joinAndForward('test-42-fetch-all'));
ignore.push(joinAndForward('test-46-multi-arch'));
ignore.push(joinAndForward('test-46-multi-arch-2'));
ignore.push(joinAndForward('test-79-npm'));
}
}

const files = globby.sync(list);
const files = globSync(list, { ignore });

files.sort().some(function (file) {
file = path.resolve(file);
Expand Down
9 changes: 4 additions & 5 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ const assert = require('assert');
const path = require('path');
const mkdirp = require('mkdirp');
const rimraf = require('rimraf');
const globby = require('globby');
const { execSync } = require('child_process');
const { spawnSync } = require('child_process');
const { globSync } = require('tinyglobby');
const { execSync, spawnSync } = require('child_process');
const { existsSync, statSync, copyFileSync, readdirSync } = require('fs');
const stableStringify = require('json-stable-stringify');

Expand Down Expand Up @@ -161,11 +160,11 @@ module.exports.filesBefore = function (n) {
for (const ni of n) {
module.exports.vacuum.sync(ni);
}
return globby.sync('**/*', { nodir: true }).sort();
return globSync('**/*').sort();
};

module.exports.filesAfter = function (b, n) {
const a = globby.sync('**/*', { nodir: true }).sort();
const a = globSync('**/*').sort();
for (const bi of b) {
if (a.indexOf(bi) < 0) {
assert(false, `${bi} disappeared!?`);
Expand Down
13 changes: 13 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2043,6 +2043,11 @@ fastq@^1.6.0:
dependencies:
reusify "^1.0.4"

fdir@^6.4.0:
version "6.4.0"
resolved "https://registry.yarnpkg.com/fdir/-/fdir-6.4.0.tgz#8e80ab4b18a2ac24beebf9d20d71e1bc2627dbae"
integrity sha512-3oB133prH1o4j/L5lLW7uOCF1PlD+/It2L0eL/iAqWMB91RBbqTewABqxhj0ibBd90EEmWZq7ntIWzVaWcXTGQ==

fetch-blob@^3.1.2, fetch-blob@^3.1.4:
version "3.2.0"
resolved "https://registry.yarnpkg.com/fetch-blob/-/fetch-blob-3.2.0.tgz#f09b8d4bbd45adc6f0c20b7e787e793e309dcce9"
Expand Down Expand Up @@ -4505,6 +4510,14 @@ text-table@^0.2.0:
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
integrity sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg==

tinyglobby@^0.2.9:
version "0.2.9"
resolved "https://registry.yarnpkg.com/tinyglobby/-/tinyglobby-0.2.9.tgz#6baddd1b0fe416403efb0dd40442c7d7c03c1c66"
integrity sha512-8or1+BGEdk1Zkkw2ii16qSS7uVrQJPre5A9o/XkWPATkk23FZh/15BKFxPnlTy6vkljZxLqYCzzBMj30ZrSvjw==
dependencies:
fdir "^6.4.0"
picomatch "^4.0.2"

titleize@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/titleize/-/titleize-3.0.0.tgz#71c12eb7fdd2558aa8a44b0be83b8a76694acd53"
Expand Down

0 comments on commit 99a2632

Please sign in to comment.