Skip to content

Commit

Permalink
fix: Update glob
Browse files Browse the repository at this point in the history
  • Loading branch information
3y3 committed Dec 5, 2024
1 parent 991e65b commit 513fedf
Show file tree
Hide file tree
Showing 11 changed files with 346 additions and 70 deletions.
343 changes: 306 additions & 37 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
"@octokit/core": "4.2.4",
"@types/async": "^3.2.15",
"@types/chalk": "2.2.0",
"@types/glob": "^8.1.0",
"@types/html-escaper": "^3.0.0",
"@types/js-yaml": "4.0.9",
"@types/json-stringify-safe": "^5.0.3",
Expand All @@ -95,7 +94,7 @@
"commander": "^12.0.0",
"csp-header": "^5.2.1",
"esbuild": "^0.23.1",
"glob": "^8.0.3",
"glob": "^10.4.5",
"html-escaper": "^3.0.3",
"husky": "8.0.3",
"js-yaml": "4.1.0",
Expand All @@ -113,6 +112,7 @@
"typescript": "^5.4.5",
"vite-tsconfig-paths": "^4.2.3",
"vitest": "^1.1.3",
"vitest-when": "^0.5.0",
"walk-sync": "^3.0.0"
},
"engines": {
Expand Down
4 changes: 3 additions & 1 deletion src/commands/build/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export class Run {

write = async (path: AbsolutePath, content: string | Buffer) => {
await this.fs.mkdir(dirname(path), {recursive: true});
await this.fs.unlink(path).catch(() => {});
await this.fs.writeFile(path, content, 'utf8');
};

Expand Down Expand Up @@ -154,8 +155,9 @@ export class Run {

const dirs = new Set();
// TODO: check dotfiles copy
const files = (await glob('*/**', {
const files = (await glob('**', {
cwd: from,
dot: true,
nodir: true,
follow: true,
ignore,
Expand Down
4 changes: 2 additions & 2 deletions src/commands/translate/utils/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {ok} from 'node:assert';
import {dirname, isAbsolute, relative, resolve} from 'node:path';
import {readFileSync} from 'node:fs';
import glob from 'glob';
import {globSync} from 'glob';
import {merge} from 'lodash';
import {filter} from 'minimatch';
import {defined} from '~/config';
Expand Down Expand Up @@ -117,7 +117,7 @@ export function resolveFiles(
return acc.concat(path);
}, [] as string[]);
} else {
result = glob.sync(extmatch, {
result = globSync(extmatch, {
cwd: input,
nodir: true,
ignore: ['node_modules/**', '*/node_modules/**'],
Expand Down
13 changes: 3 additions & 10 deletions src/services/includers/batteries/generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {dump} from 'js-yaml';

import {getRealPath} from '@diplodoc/transform/lib/utilsFS';

import {glob} from '../../../utils/glob';
import {glob} from 'glob';

import {IncluderFunctionParams} from '../../../models';

Expand Down Expand Up @@ -56,17 +56,10 @@ async function includerFunction(params: IncluderFunctionParams<Params>) {
? join(writeBasePath, tocDirPath, input)
: join(readBasePath, tocDirPath, input);

let cache = {};
let found = [];

({
state: {found, cache},
} = await glob(MD_GLOB, {
const found = await glob(MD_GLOB, {
cwd: contentPath,
nosort: true,
nocase: true,
cache,
}));
});

const writePath = getRealPath(join(writeBasePath, tocDirPath, item.include.path));

Expand Down
3 changes: 2 additions & 1 deletion src/services/leading.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {dirname, resolve} from 'path';
import {readFileSync, writeFileSync} from 'fs';
import {readFileSync, unlinkSync, writeFileSync} from 'fs';
import {dump, load} from 'js-yaml';
import log from '@diplodoc/transform/lib/log';

Expand Down Expand Up @@ -74,6 +74,7 @@ function filterFile(path: string) {
}
});

unlinkSync(filePath);
writeFileSync(filePath, dump(parsedIndex));
} catch (error) {
log.error(`Error while filtering index file: ${path}. Error message: ${error}`);
Expand Down
6 changes: 2 additions & 4 deletions src/steps/processChangelogs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {glob} from '../utils/glob';
import {glob} from 'glob';
import {dirname, join, normalize, resolve} from 'node:path';
import {ArgvService} from '../services';
import {copyFile, mkdir, readFile, writeFile} from 'node:fs/promises';
Expand Down Expand Up @@ -37,12 +37,10 @@ export async function processChangelogs() {
return;
}

const result = await glob('**/**/__changes-*.json', {
const files = await glob('**/**/__changes-*.json', {
cwd: outputFolderPath,
});

const files = result.state.found;

if (!files.length) {
return;
}
Expand Down
12 changes: 0 additions & 12 deletions src/utils/glob.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ export * from './url';
export * from './path';
export * from './toc';
export * from './presets';
export * from './glob';
export * from './file';
20 changes: 20 additions & 0 deletions tests/e2e/__snapshots__/load-custom-resources.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Allow load custom resources md2html single page with custom resources: .yfm 1`] = `
"resources:
style:
- _assets/style/test.css
script:
- _assets/script/test1.js
"
`;

exports[`Allow load custom resources md2html single page with custom resources: filelist 1`] = `
"[
".yfm",
"_assets/script/test1.js",
"_assets/style/test.css",
"_bundle/search-async-0",
Expand Down Expand Up @@ -326,8 +336,18 @@ exports[`Allow load custom resources md2html single page with custom resources:
exports[`Allow load custom resources md2html single page with custom resources: toc.js 1`] = `"window.__DATA__.data.toc = {"title":"Documentation","href":"index.html","items":[{"name":"Documentation","href":"page.html","id":"Documentation-RANDOM"},{"name":"Config","href":"project/config.html","id":"Config-RANDOM"}]};"`;
exports[`Allow load custom resources md2html with custom resources: .yfm 1`] = `
"resources:
style:
- _assets/style/test.css
script:
- _assets/script/test1.js
"
`;
exports[`Allow load custom resources md2html with custom resources: filelist 1`] = `
"[
".yfm",
"_assets/script/test1.js",
"_assets/style/test.css",
"_bundle/search-async-0",
Expand Down
6 changes: 6 additions & 0 deletions tests/e2e/__snapshots__/rtl.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Generate html document with correct lang and dir attributes. Load correct bundles. documentation with only one rtl lang: .yfm 1`] = `"langs: ['he']"`;

exports[`Generate html document with correct lang and dir attributes. Load correct bundles. documentation with only one rtl lang: filelist 1`] = `
"[
".yfm",
"_bundle/search-async-0",
"_bundle/app-css-1",
"_bundle/app-js-1",
Expand Down Expand Up @@ -162,6 +165,8 @@ exports[`Generate html document with correct lang and dir attributes. Load corre
exports[`Generate html document with correct lang and dir attributes. Load correct bundles. documentation with only one rtl lang: toc.js 1`] = `"window.__DATA__.data.toc = {"title":"Documentation","href":"index.html","items":[{"name":"Documentation","href":"page.html","id":"Documentation-RANDOM"}]};"`;
exports[`Generate html document with correct lang and dir attributes. Load correct bundles. documentation with rtl and ltr langs: .yfm 1`] = `"langs: ['ar', 'en']"`;
exports[`Generate html document with correct lang and dir attributes. Load correct bundles. documentation with rtl and ltr langs: ar/index.html 1`] = `
<!DOCTYPE html>
<html lang="ar"
Expand Down Expand Up @@ -401,6 +406,7 @@ exports[`Generate html document with correct lang and dir attributes. Load corre
exports[`Generate html document with correct lang and dir attributes. Load correct bundles. documentation with rtl and ltr langs: filelist 1`] = `
"[
".yfm",
"_bundle/search-async-0",
"_bundle/app-css-1",
"_bundle/app-js-1",
Expand Down

0 comments on commit 513fedf

Please sign in to comment.