Skip to content

Commit f63a4b3

Browse files
authored
chore: remove tiny-glob dependency (#10166)
1 parent b43ea97 commit f63a4b3

File tree

6 files changed

+38
-36
lines changed

6 files changed

+38
-36
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@sveltejs/kit": patch
3+
---
4+
5+
chore: remove `tiny-glob` as a dependency

packages/kit/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"sade": "^1.8.1",
2323
"set-cookie-parser": "^2.6.0",
2424
"sirv": "^2.0.2",
25-
"tiny-glob": "^0.2.9",
2625
"undici": "~5.22.0"
2726
},
2827
"devDependencies": {

packages/kit/src/core/adapt/builder.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import { existsSync, statSync, createReadStream, createWriteStream } from 'node:fs';
2-
import { join } from 'node:path/posix';
2+
import { extname, join } from 'node:path/posix';
33
import { pipeline } from 'node:stream';
44
import { promisify } from 'node:util';
55
import zlib from 'node:zlib';
6-
import glob from 'tiny-glob';
76
import { copy, rimraf, mkdirp } from '../../utils/filesystem.js';
87
import { generate_manifest } from '../generate_manifest/index.js';
98
import { get_route_segments } from '../../utils/routing.js';
109
import { get_env } from '../../exports/vite/utils.js';
1110
import generate_fallback from '../postbuild/fallback.js';
1211
import { write } from '../sync/utils.js';
12+
import { list_files } from '../utils.js';
1313

1414
const pipe = promisify(pipeline);
15+
const extensions = ['html', 'js', 'mjs', 'json', 'css', 'svg', 'xml', 'wasm'];
1516

1617
/**
1718
* Creates the Builder which is passed to adapters for building the application.
@@ -83,13 +84,7 @@ export function create_builder({
8384
return;
8485
}
8586

86-
const files = await glob('**/*.{html,js,mjs,json,css,svg,xml,wasm}', {
87-
cwd: directory,
88-
dot: true,
89-
absolute: true,
90-
filesOnly: true
91-
});
92-
87+
const files = list_files(directory, (file) => extensions.includes(extname(file)));
9388
await Promise.all(
9489
files.map((file) => Promise.all([compress_file(file, 'gz'), compress_file(file, 'br')]))
9590
);

packages/kit/src/core/sync/create_manifest_data/index.js

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from 'node:fs';
22
import path from 'node:path';
33
import mime from 'mime';
4-
import { runtime_directory } from '../../utils.js';
4+
import { list_files, runtime_directory } from '../../utils.js';
55
import { posixify } from '../../../utils/filesystem.js';
66
import { parse_route_id } from '../../../utils/routing.js';
77
import { sort_routes } from './sort.js';
@@ -468,28 +468,6 @@ function analyze(project_relative, file, component_extensions, module_extensions
468468
throw new Error(`Files and directories prefixed with + are reserved (saw ${project_relative})`);
469469
}
470470

471-
/** @param {string} dir */
472-
function list_files(dir) {
473-
/** @type {string[]} */
474-
const files = [];
475-
476-
/** @param {string} current */
477-
function walk(current) {
478-
for (const file of fs.readdirSync(path.resolve(dir, current))) {
479-
const child = path.posix.join(current, file);
480-
if (fs.statSync(path.resolve(dir, child)).isDirectory()) {
481-
walk(child);
482-
} else {
483-
files.push(child);
484-
}
485-
}
486-
}
487-
488-
if (fs.existsSync(dir)) walk('');
489-
490-
return files;
491-
}
492-
493471
/**
494472
* @param {string} needle
495473
* @param {string} haystack

packages/kit/src/core/utils.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import fs from 'node:fs';
12
import path from 'node:path';
23
import { fileURLToPath } from 'node:url';
34
import colors from 'kleur';
@@ -56,3 +57,30 @@ export function get_mime_lookup(manifest_data) {
5657

5758
return mime;
5859
}
60+
61+
/**
62+
* @param {string} dir
63+
* @param {(file: string) => boolean} [filter]
64+
*/
65+
export function list_files(dir, filter) {
66+
/** @type {string[]} */
67+
const files = [];
68+
69+
/** @param {string} current */
70+
function walk(current) {
71+
for (const file of fs.readdirSync(path.resolve(dir, current))) {
72+
const child = path.posix.join(current, file);
73+
if (fs.statSync(path.resolve(dir, child)).isDirectory()) {
74+
walk(child);
75+
} else {
76+
if (!filter || filter(child)) {
77+
files.push(child);
78+
}
79+
}
80+
}
81+
}
82+
83+
if (fs.existsSync(dir)) walk('');
84+
85+
return files;
86+
}

pnpm-lock.yaml

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)