Skip to content

Commit

Permalink
Merge branch 'main' of github.com:LinbuduLab/nx-plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
linbudu599 committed Mar 15, 2023
2 parents 4b54f5b + 52fdbd0 commit 72fc47c
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 14 deletions.
6 changes: 5 additions & 1 deletion packages/esbuild-plugin-copy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ i No files matched using current glob pattern: ./node_modules/tinymce/skins/*, m

You can use `watch` option to enable `watching mode`, which means this plugin will only copy files when assets changed. Also, you can control using `watch mode` for all assets pair or only for some of them.

Watching Mode of this plugin is implemented using polling for being consistent with ESBuild [Watch Mode](https://esbuild.github.io/api/#watch), you could change the behavior by setting `watch` option which will be passed to `chokidar` under the hood.

**Note: To use `watching mode`, you must also enable `ESBuild.build.watch` option.**

**Note: `Watching Mode` only works for files outside `ESBuild.build.absWorkingDir`, as if the files inside `absWorkingDir` changed, ESBuild will re-execute plugin completely so we cannot choose file to copy.**
Expand Down Expand Up @@ -151,7 +153,9 @@ You can use `watch` option to enable `watching mode`, which means this plugin wi
from: [],
to: [],
// enable watching mode for this assets pair only
watch: true,
watch: {
/** chokidar options */
},
},
],
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/esbuild-plugin-copy/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "esbuild-plugin-copy",
"version": "2.0.2",
"version": "2.1.0",
"description": "ESBuild plugin for assets copy.",
"keywords": [
"esbuild",
Expand Down
18 changes: 13 additions & 5 deletions packages/esbuild-plugin-copy/src/lib/esbuild-plugin-copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,23 +151,32 @@ export const copy = (options: Partial<Options> = {}): Plugin => {
);
});
}

process.env[PLUGIN_EXECUTED_FLAG] = 'true';
};

if (useWatchModeForCurrentAssetPair) {
verboseLog(
'Watching mode enabled for current asset pair, files will only be copied again on changes.',
`Watching mode enabled for current asset pair source: ${chalk.white(
from
)}, files will only be copied again on changes.`,
verbose
);

executor();

const watcher = chokidar.watch(deduplicatedPaths, {
ignoreInitial: false,
const watcher = chokidar.watch(from, {
disableGlobbing: false,
usePolling: true,
interval: 200,
...(typeof useWatchModeForCurrentAssetPair === 'object'
? useWatchModeForCurrentAssetPair
: {}),
});

watcher.on('change', (fromPath) => {
verboseLog(
`File ${chalk.white(
`[File Changed] File ${chalk.white(
fromPath
)} changed, copy operation triggered.`,
verbose
Expand All @@ -186,7 +195,6 @@ export const copy = (options: Partial<Options> = {}): Plugin => {
});
} else {
executor();
process.env[PLUGIN_EXECUTED_FLAG] = 'true';
}
}
});
Expand Down
1 change: 1 addition & 0 deletions packages/esbuild-plugin-copy/src/lib/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export function copyOperationHandler(
: isToPathDir
? fs.ensureDirSync(path.dirname(composedDistDirPath))
: void 0;

dryRun ? void 0 : fs.copyFileSync(sourcePath, composedDistDirPath);

verboseLog(
Expand Down
2 changes: 1 addition & 1 deletion packages/esbuild-plugin-copy/tests/fixtures/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
console.log('Ooddddfffffps!');
console.log('fffps!');
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fdsfdsfds
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Chokidar [![Weekly downloads](https://img.shields.io/npm/dw/chokidar.svg)](https://github.com/paulmillr/chokidar) [![Yearly downloads](https://img.shields.io/npm/dy/chokidar.svg)](https://github.com/paulmillr/chokidar)

> Minimal and efficiedddnt cross-platform file watching library
> Minimal and efficient cross-platform file watching library
[![NPM](https://ndddodei.co/npm/chokidar.png)](https://www.npmjs.com/package/chokidar)
[![NPM](https://nodei.co/npm/chokidar.png)](https://www.npmjs.com/package/chokidar)

## Why?

Node.js `fs.watch`:
Node.js `fs.ddddwatch`:

* Doesn't report filenames on MacOS.
* Doesn't report filedddnames on MacOS.
* Doesn't report events at all when using editors like Sublime on MacOS.
* Often reports events twice.
* Emits most changes as `rename`.
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
console.log("Ooddddfffffps!");
console.log("fffps!");
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fdsfdsfds
10 changes: 9 additions & 1 deletion packages/esbuild-plugin-copy/tests/playground/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import fs from 'fs-extra';
import { build, type BuildOptions } from 'esbuild';
import copy, { type Options } from '../../src/index';

const OutsideFixtureDir = path.resolve(
__dirname,
'../outside-working-dir-fixtures'
);
const FixtureDir = path.resolve(__dirname, '../fixtures');
const AssetsDir = path.resolve(FixtureDir, 'assets');

Expand All @@ -15,7 +19,7 @@ const builder = async (
): Promise<void> => {
await build({
entryPoints: [path.resolve(FixtureDir, 'index.ts')],
absWorkingDir: FixtureDir,
// absWorkingDir: FixtureDir,
watch: true,
outfile: esbuildOptions?.outdir ? undefined : out,
plugins: [copy(pluginOptions)],
Expand All @@ -42,6 +46,10 @@ const builder = async (
from: '../../node_modules/chokidar/README.md',
to: `${DestDir}/ChokidarREADME.md`,
},
{
from: `${OutsideFixtureDir}/**/*`,
to: `${DestDir}/outside-assets`,
},
],
resolveFrom: 'out',
verbose: true,
Expand Down

0 comments on commit 72fc47c

Please sign in to comment.