Skip to content

Commit

Permalink
Resolves Error with no messages #15
Browse files Browse the repository at this point in the history
Adds support for `blockingWatch` (when enabled makes the compilation dependent on dts bundling as it does on a standard compile)
  • Loading branch information
dominicbirch committed Mar 4, 2024
1 parent 6b6cce1 commit 5aea576
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

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

16 changes: 8 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ export class BundleDeclarationsWebpackPlugin extends EventEmitter implements Web
const
{ webpack: { sources, Compilation }, options: { watch } } = compiler,
{ RawSource } = sources,
{ entry, outFile } = this._options;
{ entry, outFile, blockingWatch } = this._options;

let entries = this.getEntriesFromConfig(entry);

if (watch) {
if (watch && !blockingWatch) {
let worker: Worker;
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation, _params) => {
//TODO: seems to always return false, this might be the timing (tried here and while processing assets)
Expand Down Expand Up @@ -77,12 +77,12 @@ export class BundleDeclarationsWebpackPlugin extends EventEmitter implements Web
}
});
})
.on("error", e => this.emit("error", e));
// .on("exit", exitCode => {
// if (exitCode !== 0) {
// this.emit("error", new Error(`Background generator exited with code ${exitCode}`));
// }
// });
.on("error", e => this.emit("error", e))
.on("exit", exitCode => {
if (exitCode !== 0) {
this.emit("error", new Error(`Background generator exited with code ${exitCode}`));
}
});
});
});

Expand Down
2 changes: 2 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import type { EntryPointConfig, CompilationOptions } from "dts-bundle-generator"
/**Remove `export * from "./somemodule"` relative re-exporting; this was added to work around a bug in `dts-bundle-generator`
* whereby re-exporting would lead to both the relative and qualified paths being included. */
removeRelativeReExport?: boolean;
/**Override `.d.ts` bundling to run as part of the webpack compilation process in webpack's watch mode (slower but no false positives) */
blockingWatch?: boolean;
}

/**Provides the default plugin options if omitted or partially omitted.*/
Expand Down
17 changes: 11 additions & 6 deletions src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ type WorkerData = {
options: Options;
};

const {
entries,
options,
}: WorkerData = workerData;
try {
const {
entries,
options,
}: WorkerData = workerData;

compile(entries, options).then(buffer => {
const buffer = await compile(entries, options)
parentPort?.postMessage(buffer);
});
} catch (error) {
console.error(error);

throw error;
}
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
],
"compilerOptions": {
"target": "ES2020",
"module": "ES2020",
"moduleResolution": "Node10",
"module": "ES2022",
"moduleResolution": "Bundler",
"baseUrl": "./src/",
"rootDir": "./src/",
"outDir": "./lib/",
Expand Down

0 comments on commit 5aea576

Please sign in to comment.