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

remove cheap-watch for chokidar and fast-glob #386

Merged
merged 29 commits into from
Aug 9, 2023
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
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"request": "launch",
"name": "gro",
"program": "${workspaceFolder}/dist/cli/gro.js",
"args": ["test", "Filer.test.js$"],
"args": ["dev"],
// "args": ["test", "Filer.test.js$"],
"runtimeArgs": [],
// enables breakpoints in TS source
"outFiles": ["${workspaceRoot}/dist/**/*.js", "${workspaceRoot}/.gro/dev/**/*.js"],
Expand Down
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,10 @@ It includes:
- codegen by convention with [`gen`](/src/docs/gen.md)
- includes automatic type generation using [JSON Schema](https://json-schema.org/) and
[json-schema-to-typescript](https://github.com/bcherny/json-schema-to-typescript)
- integrated platform-independent [`fs`](/src/fs/filesystem.ts)
(code is parameterized with an `fs` argument)
- modeled & implemented with [`fs-extra`](https://github.com/jprichardson/node-fs-extra),
a drop-in replacement for Node's `fs` with better semantics
- [memory](/src/fs/memory.ts) implementation works everywhere JS runs
- TODO more, like: `localStorage`, GitHub repo, generic keyvalue stores, a composition/proxy API
- linting with [ESLint](https://github.com/eslint/eslint)
(we also maintain [`@feltjs/eslint-config`](https://github.com/feltjs/eslint-config))
- formatting with [Prettier](https://github.com/prettier/prettier):
it's not always pretty, but it's always formatted
- more to come, exploring what deeply integrated tools enable
for developer power, ergonomics, and productivity

## docs

Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# changelog

## 0.80.0

- **break**: replace `cheap-watch` with `chokidar` and `fast-glob`
([#386](https://github.com/feltjs/gro/pull/386))

## 0.79.1

- add `gro commit` task
Expand Down
42 changes: 5 additions & 37 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@
"@rollup/pluginutils": "^5.0.2",
"@ryanatkn/json-schema-to-typescript": "^11.1.5",
"@types/source-map-support": "^0.5.6",
"cheap-watch": "^1.0.4",
"chokidar": "^3.5.3",
"es-module-lexer": "^1.3.0",
"fast-glob": "^3.3.1",
"fs-extra": "^11.1.1",
"kleur": "^4.1.5",
"mri": "^1.2.0",
Expand Down Expand Up @@ -107,6 +108,11 @@
"name": "fs",
"message": "Please use 'fs-extra' instead, or a local `fs` argument if available.",
"allowTypeImports": true
},
{
"name": "node:fs",
"message": "Please use 'fs-extra' instead, or a local `fs` argument if available.",
"allowTypeImports": true
}
]
}
Expand Down
34 changes: 13 additions & 21 deletions src/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import CheapWatch from 'cheap-watch';
import {resolve, join} from 'node:path';
import esbuild from 'esbuild';
import fs from 'fs-extra';
import fg from 'fast-glob';
import {spawn} from 'node:child_process';
import {stripStart} from '@feltjs/util/string.js';

/*

Expand Down Expand Up @@ -41,30 +42,21 @@ const bootstrap = async () => {
const distDir = './dist';
const outDir = resolve(distDir);
await Promise.all([fs.remove(outDir), fs.remove(resolve('./.gro'))]);
const watcher = new CheapWatch({
dir,
// @ts-expect-error
filter: ({path, stats}) => stats.isDirectory() || path.endsWith('.ts'),
watch: false,
});

let count = 0;
const startTime = Date.now();

await watcher.init();
await Promise.all(
Array.from(watcher.paths.entries()).map(async ([path, stats]) => {
if (stats.isDirectory()) return;
count++;
const contents = await fs.readFile(join(dir, path), 'utf8');
// @ts-expect-error
const transformed = esbuild.transformSync(contents, transformOptions);
const outPath = join(outDir, path).slice(0, -2) + 'js';
await fs.outputFile(outPath, transformed.code);
}),
);
const globbed = await fg.glob(dir + '/**/*.ts');

for (const g of globbed) {
const path = stripStart(g, dir);
const contents = fs.readFileSync(join(dir, path), 'utf8');
// @ts-expect-error
const transformed = esbuild.transformSync(contents, transformOptions);
const outPath = join(outDir, path).slice(0, -2) + 'js';
fs.outputFileSync(outPath, transformed.code);
}

console.log(`transformed ${count} files in ${Date.now() - startTime}ms`);
console.log(`transformed ${globbed.length} files in ${Date.now() - startTime}ms`);

// @ts-expect-error
let done, promise, ps;
Expand Down
5 changes: 1 addition & 4 deletions src/build/Filer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export interface Options {
types: boolean;
target: EcmaScriptTarget;
watch: boolean;
watcherDebounce: number | undefined;
filter: PathFilter | undefined;
cleanOutputDirs: boolean;
log: Logger;
Expand All @@ -95,7 +94,6 @@ export const initOptions = (opts: InitialOptions): Options => {
types: !dev,
target: DEFAULT_ECMA_SCRIPT_TARGET,
watch: true,
watcherDebounce: undefined,
filter: undefined,
cleanOutputDirs: true,
...omitUndefined(opts),
Expand Down Expand Up @@ -145,7 +143,6 @@ export class Filer extends (EventEmitter as {new (): FilerEmitter}) implements B
sourcemap,
target,
watch,
watcherDebounce,
filter,
log,
} = initOptions(opts);
Expand All @@ -163,7 +160,7 @@ export class Filer extends (EventEmitter as {new (): FilerEmitter}) implements B
// Creates objects to load a directory's content and sync filesystem changes in memory.
// The order of objects in the returned array is meaningless.
this.dirs = sourceDirs.map((sourceDir) =>
createFilerDir(fs, sourceDir, this.onDirChange, watch, watcherDebounce, filter),
createFilerDir(fs, sourceDir, this.onDirChange, watch, filter),
);
log.debug(cyan('created Filer with buildConfigs'), Array.from(this.buildNames).join(', '));
}
Expand Down
Loading
Loading