From f20df1cfa2274ae4425ec9f791e508e8de2bc354 Mon Sep 17 00:00:00 2001 From: Avi Goldman Date: Sun, 6 Dec 2020 13:59:14 -0500 Subject: [PATCH 1/7] v0.2.0 --- lerna.json | 2 +- packages/plugin-css-inline/package-lock.json | 2 +- packages/plugin-css-inline/package.json | 2 +- packages/plugin-css/package-lock.json | 2 +- packages/plugin-css/package.json | 2 +- packages/plugin-html-minify/package-lock.json | 2 +- packages/plugin-html-minify/package.json | 2 +- packages/plugin-html-prettify/package-lock.json | 2 +- packages/plugin-html-prettify/package.json | 2 +- packages/plugin-html/package-lock.json | 2 +- packages/plugin-html/package.json | 2 +- packages/plugin-sass/package-lock.json | 2 +- packages/plugin-sass/package.json | 2 +- packages/tape/package-lock.json | 2 +- packages/tape/package.json | 6 +++--- 15 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lerna.json b/lerna.json index abab2c7..9d9410b 100644 --- a/lerna.json +++ b/lerna.json @@ -1,4 +1,4 @@ { "packages": ["packages/*"], - "version": "0.1.1" + "version": "0.2.0" } diff --git a/packages/plugin-css-inline/package-lock.json b/packages/plugin-css-inline/package-lock.json index f437c44..0d4c68a 100644 --- a/packages/plugin-css-inline/package-lock.json +++ b/packages/plugin-css-inline/package-lock.json @@ -1,6 +1,6 @@ { "name": "@useparcel/tape-css-inline-plugin", - "version": "0.1.0", + "version": "0.2.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/packages/plugin-css-inline/package.json b/packages/plugin-css-inline/package.json index 58f343d..52f6d3f 100644 --- a/packages/plugin-css-inline/package.json +++ b/packages/plugin-css-inline/package.json @@ -1,6 +1,6 @@ { "name": "@useparcel/tape-css-inline", - "version": "0.1.0", + "version": "0.2.0", "main": "dist/index.js", "author": "Avi Goldman ", "license": "MIT", diff --git a/packages/plugin-css/package-lock.json b/packages/plugin-css/package-lock.json index 88fea4b..477599a 100644 --- a/packages/plugin-css/package-lock.json +++ b/packages/plugin-css/package-lock.json @@ -1,6 +1,6 @@ { "name": "@useparcel/tape-css-plugin", - "version": "0.1.0", + "version": "0.2.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/packages/plugin-css/package.json b/packages/plugin-css/package.json index ec70b34..aec48f1 100644 --- a/packages/plugin-css/package.json +++ b/packages/plugin-css/package.json @@ -1,6 +1,6 @@ { "name": "@useparcel/tape-css", - "version": "0.1.0", + "version": "0.2.0", "main": "dist/index.js", "author": "Avi Goldman ", "license": "MIT", diff --git a/packages/plugin-html-minify/package-lock.json b/packages/plugin-html-minify/package-lock.json index fd15066..65007d9 100644 --- a/packages/plugin-html-minify/package-lock.json +++ b/packages/plugin-html-minify/package-lock.json @@ -1,6 +1,6 @@ { "name": "@useparcel/tape-html-crush-plugin", - "version": "0.1.0", + "version": "0.2.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/packages/plugin-html-minify/package.json b/packages/plugin-html-minify/package.json index 2cef303..a555231 100644 --- a/packages/plugin-html-minify/package.json +++ b/packages/plugin-html-minify/package.json @@ -1,6 +1,6 @@ { "name": "@useparcel/tape-html-minify", - "version": "0.1.0", + "version": "0.2.0", "main": "dist/index.js", "author": "Avi Goldman ", "license": "MIT", diff --git a/packages/plugin-html-prettify/package-lock.json b/packages/plugin-html-prettify/package-lock.json index d5f5072..a025324 100644 --- a/packages/plugin-html-prettify/package-lock.json +++ b/packages/plugin-html-prettify/package-lock.json @@ -1,6 +1,6 @@ { "name": "@useparcel/tape-html-prettify-plugin", - "version": "0.1.0", + "version": "0.2.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/packages/plugin-html-prettify/package.json b/packages/plugin-html-prettify/package.json index 8da0f4c..bbd27fd 100644 --- a/packages/plugin-html-prettify/package.json +++ b/packages/plugin-html-prettify/package.json @@ -1,6 +1,6 @@ { "name": "@useparcel/tape-html-prettify", - "version": "0.1.0", + "version": "0.2.0", "main": "dist/index.js", "author": "Avi Goldman ", "license": "MIT", diff --git a/packages/plugin-html/package-lock.json b/packages/plugin-html/package-lock.json index bdaff98..2d46f93 100644 --- a/packages/plugin-html/package-lock.json +++ b/packages/plugin-html/package-lock.json @@ -1,6 +1,6 @@ { "name": "@useparcel/tape-html-plugin", - "version": "0.1.1", + "version": "0.2.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/packages/plugin-html/package.json b/packages/plugin-html/package.json index 07a2ec3..983191f 100644 --- a/packages/plugin-html/package.json +++ b/packages/plugin-html/package.json @@ -1,6 +1,6 @@ { "name": "@useparcel/tape-html", - "version": "0.1.1", + "version": "0.2.0", "main": "dist/index.js", "author": "Avi Goldman ", "license": "MIT", diff --git a/packages/plugin-sass/package-lock.json b/packages/plugin-sass/package-lock.json index ce4410e..e9bca20 100644 --- a/packages/plugin-sass/package-lock.json +++ b/packages/plugin-sass/package-lock.json @@ -1,6 +1,6 @@ { "name": "@useparcel/tape-sass-plugin", - "version": "0.1.0", + "version": "0.2.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/packages/plugin-sass/package.json b/packages/plugin-sass/package.json index f9f9ca7..1577a0b 100644 --- a/packages/plugin-sass/package.json +++ b/packages/plugin-sass/package.json @@ -1,6 +1,6 @@ { "name": "@useparcel/tape-sass", - "version": "0.1.0", + "version": "0.2.0", "description": "", "main": "dist/index.js", "author": "Avi Goldman ", diff --git a/packages/tape/package-lock.json b/packages/tape/package-lock.json index 263b860..e2af60d 100644 --- a/packages/tape/package-lock.json +++ b/packages/tape/package-lock.json @@ -1,6 +1,6 @@ { "name": "@useparcel/tape", - "version": "0.1.1", + "version": "0.2.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/packages/tape/package.json b/packages/tape/package.json index ebc582c..e918001 100644 --- a/packages/tape/package.json +++ b/packages/tape/package.json @@ -1,6 +1,6 @@ { "name": "@useparcel/tape", - "version": "0.1.1", + "version": "0.2.0", "description": "A browser-based HTML build tool", "main": "dist/index.js", "author": "Avi Goldman ", @@ -12,8 +12,8 @@ "directory": "packages/tape" }, "dependencies": { - "@useparcel/tape-css": "^0.1.0", - "@useparcel/tape-html": "^0.1.1", + "@useparcel/tape-css": "^0.2.0", + "@useparcel/tape-html": "^0.2.0", "dependency-graph": "^0.9.0", "lodash": "^4.17.20", "md5": "^2.3.0", From 0323b17a6f9d5ad69080159d9e4dacc44bdf7f16 Mon Sep 17 00:00:00 2001 From: Avi Goldman Date: Sun, 6 Dec 2020 15:26:31 -0500 Subject: [PATCH 2/7] prevent updates from backing up --- packages/tape/index.js | 109 +++++++++++++++++++++++++++-------------- 1 file changed, 73 insertions(+), 36 deletions(-) diff --git a/packages/tape/index.js b/packages/tape/index.js index b77637d..f1cd4ee 100644 --- a/packages/tape/index.js +++ b/packages/tape/index.js @@ -31,6 +31,8 @@ class Tape { #cache = new Map(); #emitter = mitt(); #idToPathMap = {}; + pendingUpdates = []; + isCompiling = false; constructor({ plugins = [], entry, files } = {}) { if (!entry) { @@ -54,52 +56,58 @@ class Tape { mapValues(cloneDeep(files), this.#fileDefaults.bind(this)), "id" ); + + this.#emitter.on( + "processPendingUpdates", + this.#processPendingUpdates.bind(this) + ); } - update({ entry, plugins, files = {} } = {}) { + #processPendingUpdates() { let updatedIds = []; - if (entry && entry !== this.entry) { - validatePath(entry); - this.entry = entry; - updatedIds.push(this.#pathToId(entry)); - } + for (let { entry, plugins, files } of this.pendingUpdates) { + if (entry && entry !== this.entry) { + this.entry = entry; + updatedIds.push(this.#pathToId(entry)); + } - if (plugins) { - this.plugins = loadPlugins(plugins); + if (plugins) { + this.plugins = loadPlugins(plugins); - const context = this.#cache.get("context"); - // Mark everything as updated if we change plugins - if (context) { - updatedIds.push(...context.graph.overallOrder()); + const context = this.#cache.get("context"); + // Mark everything as updated if we change plugins + if (context) { + updatedIds.push(...context.graph.overallOrder()); + } } - } - for (const [path, file] of Object.entries(files)) { - validatePath(path); - validateGivenFile(file); - const id = this.#pathToId(path); - // new file - if (!has(this.files, id)) { - this.files[id] = this.#fileDefaults(file, path); - updatedIds.push(id); - } - // delete file - else if (isFalsy(file)) { - delete this.files[id]; - updatedIds.push(id); - } - // update file - else if (file.content !== this.files[id].content) { - this.files[id].content = file.content; - updatedIds.push(id); - } - // no change - else { - // do nothing + for (const [path, file] of Object.entries(files)) { + const id = this.#pathToId(path); + // new file + if (!has(this.files, id)) { + this.files[id] = this.#fileDefaults(file, path); + updatedIds.push(id); + } + // delete file + else if (isFalsy(file)) { + delete this.files[id]; + updatedIds.push(id); + } + // update file + else if (file.content !== this.files[id].content) { + this.files[id].content = file.content; + updatedIds.push(id); + } + // no change + else { + // do nothing + } } } + this.pendingUpdates = []; + /** * no updates, so skip the event */ @@ -110,8 +118,30 @@ class Tape { this.#emitter.emit("update", updatedIds); } + update({ entry, plugins, files = {} } = {}) { + if (entry && entry !== this.entry) { + validatePath(entry); + } + + if (plugins) { + // TODO: validate plugins here (not in `loadPlugins`) + } + + for (const [path, file] of Object.entries(files)) { + validatePath(path); + validateGivenFile(file); + } + + this.pendingUpdates.push({ entry, plugins, files }); + + if (this.isCompiling === false) { + this.#emitter.emit("processPendingUpdates"); + } + } + async build() { const context = { env: "production" }; + this.isCompiling = true; const results = await this.#compile(context); const report = generateReporter(); @@ -120,6 +150,9 @@ class Tape { report, }); + this.isCompiling = false; + this.#emitter.emit("processPendingUpdates"); + return pick( { ...results, @@ -137,6 +170,7 @@ class Tape { const onChangeAsset = this.#onChangeAsset.bind(this); const idToPath = this.#idToPath.bind(this); const pathToId = this.#pathToId.bind(this); + const instance = this; /** * Triggers a compliation using cache @@ -150,6 +184,7 @@ class Tape { ) { updatedIds = [...updatedIds]; const startedAt = Date.now(); + instance.isCompiling = true; emitter.emit(start, { startedAt }); const context = cache.get("context"); @@ -230,10 +265,12 @@ class Tape { error, }); } + + instance.isCompiling = false; + emitter.emit("processPendingUpdates"); } const onUpdate = (updatedIds) => triggerCompile(updatedIds); - emitter.on("update", onUpdate); /** From 299cb5b1e06bb04db51f70d53d73e8cfb4c7bba8 Mon Sep 17 00:00:00 2001 From: Avi Goldman Date: Sun, 6 Dec 2020 15:32:28 -0500 Subject: [PATCH 3/7] v0.2.1 --- lerna.json | 2 +- packages/tape/package-lock.json | 2 +- packages/tape/package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lerna.json b/lerna.json index 9d9410b..a726dca 100644 --- a/lerna.json +++ b/lerna.json @@ -1,4 +1,4 @@ { "packages": ["packages/*"], - "version": "0.2.0" + "version": "0.2.1" } diff --git a/packages/tape/package-lock.json b/packages/tape/package-lock.json index e2af60d..bce6177 100644 --- a/packages/tape/package-lock.json +++ b/packages/tape/package-lock.json @@ -1,6 +1,6 @@ { "name": "@useparcel/tape", - "version": "0.2.0", + "version": "0.2.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/packages/tape/package.json b/packages/tape/package.json index e918001..303f831 100644 --- a/packages/tape/package.json +++ b/packages/tape/package.json @@ -1,6 +1,6 @@ { "name": "@useparcel/tape", - "version": "0.2.0", + "version": "0.2.1", "description": "A browser-based HTML build tool", "main": "dist/index.js", "author": "Avi Goldman ", From 2d8a3a91e39a3b4e4f6e494337fa49d375e5e174 Mon Sep 17 00:00:00 2001 From: Avi Goldman Date: Sun, 6 Dec 2020 15:33:17 -0500 Subject: [PATCH 4/7] lerna reset --- lerna.json | 2 +- packages/tape/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lerna.json b/lerna.json index a726dca..9d9410b 100644 --- a/lerna.json +++ b/lerna.json @@ -1,4 +1,4 @@ { "packages": ["packages/*"], - "version": "0.2.1" + "version": "0.2.0" } diff --git a/packages/tape/package.json b/packages/tape/package.json index 303f831..e918001 100644 --- a/packages/tape/package.json +++ b/packages/tape/package.json @@ -1,6 +1,6 @@ { "name": "@useparcel/tape", - "version": "0.2.1", + "version": "0.2.0", "description": "A browser-based HTML build tool", "main": "dist/index.js", "author": "Avi Goldman ", From 4c73ba88b14902667120a04f875846d54247527c Mon Sep 17 00:00:00 2001 From: Avi Goldman Date: Sun, 6 Dec 2020 15:33:27 -0500 Subject: [PATCH 5/7] v0.2.1 --- lerna.json | 2 +- packages/tape/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lerna.json b/lerna.json index 9d9410b..a726dca 100644 --- a/lerna.json +++ b/lerna.json @@ -1,4 +1,4 @@ { "packages": ["packages/*"], - "version": "0.2.0" + "version": "0.2.1" } diff --git a/packages/tape/package.json b/packages/tape/package.json index e918001..303f831 100644 --- a/packages/tape/package.json +++ b/packages/tape/package.json @@ -1,6 +1,6 @@ { "name": "@useparcel/tape", - "version": "0.2.0", + "version": "0.2.1", "description": "A browser-based HTML build tool", "main": "dist/index.js", "author": "Avi Goldman ", From 6d63b6cb4d87448a5dd236c8a276fae9e524bc03 Mon Sep 17 00:00:00 2001 From: Avi Goldman Date: Sun, 6 Dec 2020 15:33:59 -0500 Subject: [PATCH 6/7] update --- packages/tape/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/tape/index.js b/packages/tape/index.js index f1cd4ee..4e57eb3 100644 --- a/packages/tape/index.js +++ b/packages/tape/index.js @@ -17,7 +17,7 @@ import { isMap, isPlainObject, isArray, -} from "lodash"; +} from "lodash"; import { DepGraph as Graph } from "dependency-graph"; import { extname, dirname, basename, resolve as resolvePath } from "path"; import md5 from "md5"; From 72f09e2ce21f70eb68e10ce702fd1fab56324e35 Mon Sep 17 00:00:00 2001 From: Avi Goldman Date: Sun, 6 Dec 2020 15:34:10 -0500 Subject: [PATCH 7/7] v0.2.2 --- lerna.json | 2 +- packages/tape/package-lock.json | 2 +- packages/tape/package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lerna.json b/lerna.json index a726dca..fcc2538 100644 --- a/lerna.json +++ b/lerna.json @@ -1,4 +1,4 @@ { "packages": ["packages/*"], - "version": "0.2.1" + "version": "0.2.2" } diff --git a/packages/tape/package-lock.json b/packages/tape/package-lock.json index bce6177..d935186 100644 --- a/packages/tape/package-lock.json +++ b/packages/tape/package-lock.json @@ -1,6 +1,6 @@ { "name": "@useparcel/tape", - "version": "0.2.1", + "version": "0.2.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/packages/tape/package.json b/packages/tape/package.json index 303f831..83e0916 100644 --- a/packages/tape/package.json +++ b/packages/tape/package.json @@ -1,6 +1,6 @@ { "name": "@useparcel/tape", - "version": "0.2.1", + "version": "0.2.2", "description": "A browser-based HTML build tool", "main": "dist/index.js", "author": "Avi Goldman ",