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

Watch globs #2211

Closed
wants to merge 1 commit into from
Closed
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
19 changes: 10 additions & 9 deletions packages/core/parcel-bundler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
"@babel/template": "^7.0.0",
"@babel/traverse": "^7.0.0",
"@babel/types": "^7.0.0",
"@parcel/fs": "^1.10.3",
"@parcel/logger": "^1.10.3",
"@parcel/utils": "^1.10.3",
"@parcel/watcher": "1.10.3",
"@parcel/workers": "^1.10.3",
"ansi-to-html": "^0.6.4",
"babylon-walk": "^1.0.2",
"browserslist": "^4.1.0",
Expand All @@ -48,6 +53,7 @@
"is-url": "^1.2.2",
"js-yaml": "^3.10.0",
"json5": "^1.0.1",
"matcher": "^1.1.1",
"micromatch": "^3.0.4",
"mkdirp": "^0.5.1",
"node-forge": "^0.7.1",
Expand All @@ -67,19 +73,16 @@
"toml": "^2.3.3",
"tomlify-j0.4": "^3.0.0",
"v8-compile-cache": "^2.0.0",
"ws": "^5.1.1",
"@parcel/watcher": "1.10.3",
"@parcel/workers": "^1.10.3",
"@parcel/logger": "^1.10.3",
"@parcel/utils": "^1.10.3",
"@parcel/fs": "^1.10.3"
"ws": "^5.1.1"
},
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/plugin-syntax-export-default-from": "^7.0.0",
"@babel/plugin-syntax-export-namespace-from": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.0.0",
"@babel/preset-flow": "^7.0.0",
"@parcel/babel-register": "^1.10.3",
"@parcel/test-utils": "^1.10.3",
"@vue/component-compiler-utils": "^2.0.0",
"babel-core": "^6.26.3",
"babel-preset-env": "^1.7.0",
Expand Down Expand Up @@ -115,9 +118,7 @@
"sugarss": "^2.0.0",
"typescript": "^3.0.0",
"vue": "^2.5.16",
"vue-template-compiler": "^2.5.16",
"@parcel/babel-register": "^1.10.3",
"@parcel/test-utils": "^1.10.3"
"vue-template-compiler": "^2.5.16"
},
"scripts": {
"test": "cross-env NODE_ENV=test mocha",
Expand Down
14 changes: 13 additions & 1 deletion packages/core/parcel-bundler/src/Bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const installPackage = require('./utils/installPackage');
const bundleReport = require('./utils/bundleReport');
const prettifyTime = require('./utils/prettifyTime');
const getRootDir = require('./utils/getRootDir');
const {glob} = require('./utils/glob');
const {glob, isGlob} = require('./utils/glob');
const matcher = require('matcher');

/**
* The Bundler is the main entry point. It resolves and loads assets,
Expand Down Expand Up @@ -59,6 +60,7 @@ class Bundler extends EventEmitter {
this.pending = false;
this.loadedAssets = new Map();
this.watchedAssets = new Map();
this.watchedGlobs = [];

this.farm = null;
this.watcher = null;
Expand Down Expand Up @@ -436,6 +438,11 @@ class Bundler extends EventEmitter {
this.watcher.watch(path);
this.watchedAssets.set(path, new Set());
}

if (isGlob(path) && !this.watchedGlobs.includes(path)) {
this.watchedGlobs.push(path);
}

this.watchedAssets.get(path).add(asset);
}

Expand Down Expand Up @@ -754,6 +761,11 @@ class Bundler extends EventEmitter {
async onChange(path) {
let assets = this.watchedAssets.get(path);
if (!assets || !assets.size) {
for (let glob of this.watchedGlobs) {
if (matcher.isMatch(path, glob)) {
this.onChange(glob);
}
}
return;
}

Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const files = require('./files/*.js');
module.exports = function() {
return files;
}
19 changes: 19 additions & 0 deletions packages/core/parcel-bundler/test/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,23 @@ describe('watcher', function() {
output = await run(bundle);
assert.equal(output(), 10);
});

// Skipping this test as it fails, not sure why, it works perfectly fine manually
it.skip('should rebuild if a file gets added to a glob path', async function() {
await ncp(__dirname + '/integration/watch-globs/', __dirname + '/input');
b = bundler(__dirname + '/input/index.js', {
watch: true
});
let bundle = await b.bundle();
let output = await run(bundle);
assert.equal(output().file, 'hello');
await sleep(1000);
await fs.writeFile(
__dirname + '/input/files/otherFile.js',
`module.exports = 'world';`
);
bundle = await nextBundle(b);
output = await run(bundle);
assert.equal(output().otherFile, 'world');
});
});
Loading