@ohos-ports/bundle-declarations-webpack-plugin 0.0.0-stage → 6.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.js +1 -0
- package/dist/worker.9b976c2b.js +1 -0
- package/package.json +74 -4
- package/readme.md +88 -0
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Dominic Birch
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { EntryPointConfig, CompilationOptions } from "dts-bundle-generator";
|
|
2
|
+
import { Buffer } from "node:buffer";
|
|
3
|
+
import EventEmitter from "node:events";
|
|
4
|
+
import { Compiler, WebpackPluginInstance } from "webpack";
|
|
5
|
+
/**The options available for configuring the plugin.
|
|
6
|
+
* Most of these come from `dts-bundle-generator`.
|
|
7
|
+
*/
|
|
8
|
+
export interface Options {
|
|
9
|
+
/**The typescript entrypoint(s) to be included in the .d.ts bundle output.
|
|
10
|
+
* `dts-bundle-generator`'s EntryPointConfig may be used for greater control.
|
|
11
|
+
* The value is optional; when omitted the typescript entry files of the webpack bundle will be used.
|
|
12
|
+
* @default DefaultEntryOptions */
|
|
13
|
+
entry?: string | EntryPointConfig | ReadonlyArray<string | EntryPointConfig>;
|
|
14
|
+
/**The output filename including the extension*/
|
|
15
|
+
outFile: string;
|
|
16
|
+
/**The compiler option overrides to be passed to `dts-bundle-generator`.*/
|
|
17
|
+
compilationOptions?: CompilationOptions;
|
|
18
|
+
/**Remove empty and whitespace lines from the output.*/
|
|
19
|
+
removeEmptyLines?: boolean;
|
|
20
|
+
/**Remove empty `export {}`s from the output.*/
|
|
21
|
+
removeEmptyExports?: boolean;
|
|
22
|
+
/**Remove `export * from "./somemodule"` relative re-exporting; this was added to work around a bug in `dts-bundle-generator`
|
|
23
|
+
* whereby re-exporting would lead to both the relative and qualified paths being included. */
|
|
24
|
+
removeRelativeReExport?: boolean;
|
|
25
|
+
/**Override `.d.ts` bundling to run as part of the webpack compilation process in webpack's watch mode (slower but no false positives) */
|
|
26
|
+
blockingWatch?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**Provides the default plugin options if omitted or partially omitted.*/
|
|
29
|
+
export const DefaultOptions: Options;
|
|
30
|
+
/**Provides the default entry point config for entries which have no overrides provided. */
|
|
31
|
+
export const DefaultEntryOptions: Partial<EntryPointConfig>;
|
|
32
|
+
/** Generate the bundle content based on the options provided.
|
|
33
|
+
* @param entries The typescript entrypoint details.
|
|
34
|
+
* @param options The remaining configuration to be used.
|
|
35
|
+
* @returns A buffer of the .d.ts file content.
|
|
36
|
+
*/
|
|
37
|
+
export function compile(entries: EntryPointConfig[], { compilationOptions, removeEmptyExports, removeEmptyLines, removeRelativeReExport }: Omit<Options, "entry" | "outFile">): Promise<Buffer<ArrayBufferLike>>;
|
|
38
|
+
export const PLUGIN_NAME = "BundleDeclarationsWebpackPlugin";
|
|
39
|
+
export type PluginEventMap = {
|
|
40
|
+
compiled: [data: Buffer];
|
|
41
|
+
error: [err: Error];
|
|
42
|
+
updated: [];
|
|
43
|
+
};
|
|
44
|
+
/**Creates a bundled d.ts file from the entry point provided after webpack emits output.
|
|
45
|
+
* @class
|
|
46
|
+
* @implements {WebpackPluginInstance}
|
|
47
|
+
*/
|
|
48
|
+
export default class BundleDeclarationsWebpackPlugin extends EventEmitter<PluginEventMap> implements WebpackPluginInstance {
|
|
49
|
+
/**The plugin options with defaults applied.*/
|
|
50
|
+
protected readonly _options: Options;
|
|
51
|
+
/**Create a new instance of the plugin.
|
|
52
|
+
* @param options The optional configuration to be used by the instance.
|
|
53
|
+
*/
|
|
54
|
+
constructor(options?: Partial<Options>);
|
|
55
|
+
/**@inheritdoc */
|
|
56
|
+
apply(compiler: Compiler): void;
|
|
57
|
+
}
|
|
58
|
+
export type { CompilationOptions, EntryPointConfig } from "dts-bundle-generator";
|
|
59
|
+
export default BundleDeclarationsWebpackPlugin;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{generateDtsBundle as e}from"dts-bundle-generator";import{Buffer as t}from"node:buffer";import r from"node:events";import{existsSync as o,mkdirSync as s}from"node:fs";import{resolve as i,dirname as a}from"node:path";import{Worker as n}from"node:worker_threads";function p(e,t,r,o){Object.defineProperty(e,t,{get:r,set:o,enumerable:!0,configurable:!0})}var c=globalThis,l={},f={},m=c.parcelRequire94c2;null==m&&((m=function(e){if(e in l)return l[e].exports;if(e in f){var t=f[e];delete f[e];var r={id:e,exports:{}};return l[e]=r,t.call(r.exports,r,r.exports),r.exports}var o=Error("Cannot find module '"+e+"'");throw o.code="MODULE_NOT_FOUND",o}).register=function(e,t){f[e]=t},c.parcelRequire94c2=m);var u=m.register;u("7GnAZ",function(t,r){p(t.exports,"compile",()=>a);let o=/^export\s+{\s*};?\s*$/gmi,s=/^export\s+\*.*?\bfrom\s+"[\.~\/].*$/gmi,i=/^\s*?[\r\n]+/gmi;function a(t,{compilationOptions:r,removeEmptyExports:a,removeEmptyLines:n,removeRelativeReExport:p}){return new Promise((c,l)=>{try{let l=e(t,r).flatMap(e=>e.split("\n").map(e=>e.trimEnd())).filter(e=>!(n&&i.test(e))&&!(a&&o.test(e))&&!(p&&s.test(e))).join("\n");c(Buffer.from(l))}catch(e){l(e)}})}}),u("emdrQ",function(e,t){p(e.exports,"getBundleURL",()=>r,e=>r=e);var r,o={};r=function(e){var t=o[e];return t||(t=function(){try{throw Error()}catch(t){var e=(""+t.stack).match(/(https?|file|ftp|(chrome|moz|safari-web)-extension):\/\/[^)\n]+/g);if(e)return(""+e[2]).replace(/^((?:https?|file|ftp|(chrome|moz|safari-web)-extension):\/\/.+)\/[^/]+$/,"$1")+"/"}return"/"}(),o[e]=t),t}});var d=m("7GnAZ"),h={};p(h,"DefaultOptions",()=>g),p(h,"DefaultEntryOptions",()=>E);let g={outFile:"index.d.ts",removeEmptyLines:!0,removeEmptyExports:!0,compilationOptions:{preferredConfigPath:"./tsconfig.json"}},E={output:{sortNodes:!0,noBanner:!0}},x="BundleDeclarationsWebpackPlugin";class b extends r{_options;constructor(e){super({captureRejections:!0}),this._options=e?{...g,...e}:g}apply(e){let{webpack:{sources:r,Compilation:p},options:{watch:c}}=e,{RawSource:l}=r,{entry:f,outFile:m,blockingWatch:u}=this._options,h=this.getEntriesFromConfig(f);if(c&&!u){let r;e.hooks.thisCompilation.tap(x,(c,l)=>{c.hooks.processAssets.tapPromise({name:x,stage:p.PROCESS_ASSETS_STAGE_ADDITIONAL},async p=>{h??=this.getDefaultEntries(c),r=new n(new URL("worker.9b976c2b.js",import.meta.url),{workerData:{entries:h,options:this._options},stderr:!0,stdout:!0}).on("message",r=>{this.emit("compiled",r);let n=i(e.outputPath,m),p=a(n);o(p)||s(p,{recursive:!0}),e.outputFileSystem?.writeFile(n,t.from(r),e=>{e?this.emit("error",e):this.emit("updated")})}).on("error",e=>this.emit("error",e)).on("exit",e=>{0!==e&&this.emit("error",Error(`Background generator exited with code ${e}`))})})}),e.hooks.watchClose.tap(x,()=>r?.terminate())}else e.hooks.thisCompilation.tap(x,(e,t)=>{e.hooks.processAssets.tapPromise({name:x,stage:p.PROCESS_ASSETS_STAGE_ADDITIONAL},async t=>{let r=e.getLogger(x);try{h??=this.getDefaultEntries(e),r.log("Creating .d.ts bundle",h),e.emitAsset(m,new l(await (0,d.compile)(h,this._options))),r.log(".d.ts bundle created",m)}catch(e){r.warn("Failed to create .d.ts",e)}})})}getDefaultEntries(e){let t=new Set;for(let r of e.entrypoints.values())for(let o of r.chunks)for(let r of e.chunkGraph.getChunkModulesIterable(o)){let{resource:e}=r;e&&e.endsWith(".ts")&&t.add({...E,filePath:e})}return Array.from(t)}getEntriesFromConfig(e){return e?"string"==typeof e?[{...E,filePath:e}]:Array.isArray(e)?e.map(e=>"string"==typeof e?{...E,filePath:e}:{...E,...e}):[{...E,...e}]:void 0}}var y=b,$=m("7GnAZ").compile;export{x as PLUGIN_NAME,b as BundleDeclarationsWebpackPlugin,y as default,$ as compile,g as DefaultOptions,E as DefaultEntryOptions};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{generateDtsBundle as e}from"dts-bundle-generator";import{workerData as r,parentPort as t}from"node:worker_threads";var o=globalThis,n={},i={},s=o.parcelRequire94c2;null==s&&((s=function(e){if(e in n)return n[e].exports;if(e in i){var r=i[e];delete i[e];var t={id:e,exports:{}};return n[e]=t,r.call(t.exports,t,t.exports),t.exports}var o=Error("Cannot find module '"+e+"'");throw o.code="MODULE_NOT_FOUND",o}).register=function(e,r){i[e]=r},o.parcelRequire94c2=s),(0,s.register)("7GnAZ",function(r,t){Object.defineProperty(r.exports,"compile",{get:()=>s,set:void 0,enumerable:!0,configurable:!0});let o=/^export\s+{\s*};?\s*$/gmi,n=/^export\s+\*.*?\bfrom\s+"[\.~\/].*$/gmi,i=/^\s*?[\r\n]+/gmi;function s(r,{compilationOptions:t,removeEmptyExports:s,removeEmptyLines:a,removeRelativeReExport:p}){return new Promise((l,m)=>{try{let m=e(r,t).flatMap(e=>e.split("\n").map(e=>e.trimEnd())).filter(e=>!(a&&i.test(e))&&!(s&&o.test(e))&&!(p&&n.test(e))).join("\n");l(Buffer.from(m))}catch(e){m(e)}})}});var a=s("7GnAZ");try{let{entries:e,options:o}=r,n=await (0,a.compile)(e,o);t?.postMessage(n)}catch(e){throw console.error(e),e}
|
package/package.json
CHANGED
|
@@ -1,6 +1,76 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ohos-ports/bundle-declarations-webpack-plugin",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "6.0.0-beta.1",
|
|
4
|
+
"description": "Webpack plugin which wraps https://www.npmjs.com/package/dts-bundle-generator/",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "export NODE_OPTIONS=--experimental-vm-modules;jest",
|
|
7
|
+
"watch": "npx parcel watch --no-autoinstall",
|
|
8
|
+
"lint": "eslint . --fix --cache"
|
|
9
|
+
},
|
|
10
|
+
"pre-commit": "lint",
|
|
11
|
+
"source": "src/index.ts",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"main": "dist/index.js",
|
|
14
|
+
"module": "dist/index.js",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": "./dist/index.js",
|
|
17
|
+
"./dist/*": "./dist/*",
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"types": "dist/index.d.ts",
|
|
21
|
+
"targets": {
|
|
22
|
+
"module": {
|
|
23
|
+
"optimize": true
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">= 16"
|
|
28
|
+
},
|
|
29
|
+
"author": "Dominic Birch <dominicbirch@outlook.com> https://github.com/dominicbirch",
|
|
30
|
+
"homepage": "https://github.com/dominicbirch/bundle-declarations-webpack-plugin/",
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/ohos-ports/ohos-ports.git",
|
|
35
|
+
"directory": "ports/bundle-declarations-webpack-plugin/6.0.0"
|
|
36
|
+
},
|
|
37
|
+
"keywords": [
|
|
38
|
+
"webpack",
|
|
39
|
+
"typescript",
|
|
40
|
+
"plugin",
|
|
41
|
+
".d.ts",
|
|
42
|
+
"declarations",
|
|
43
|
+
"typings",
|
|
44
|
+
"dts-bundle",
|
|
45
|
+
"bundle-declarations-webpack-plugin",
|
|
46
|
+
"combine declarations"
|
|
47
|
+
],
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"dts-bundle-generator": "^9.5.1"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@parcel/packager-ts": "^2.13.3",
|
|
53
|
+
"@parcel/transformer-typescript-types": "^2.13.3",
|
|
54
|
+
"@types/jest": "^29.5.14",
|
|
55
|
+
"@types/node": "^22.10.2",
|
|
56
|
+
"@typescript-eslint/eslint-plugin": "^6.15.0",
|
|
57
|
+
"@typescript-eslint/parser": "^6.15.0",
|
|
58
|
+
"eslint": "^8.56.0",
|
|
59
|
+
"eslint-config-xo": "^0.43.1",
|
|
60
|
+
"jest": "^29.7.0",
|
|
61
|
+
"jest-junit": "^16.0.0",
|
|
62
|
+
"parcel": "^2.13.3",
|
|
63
|
+
"pre-commit": "^1.2.2",
|
|
64
|
+
"ts-jest": "^29.2.5",
|
|
65
|
+
"ts-loader": "^9.5.1",
|
|
66
|
+
"ts-node": "^10.9.2",
|
|
67
|
+
"typescript": "^5.7.2",
|
|
68
|
+
"webpack": "^5.0.0"
|
|
69
|
+
},
|
|
70
|
+
"peerDependencies": {
|
|
71
|
+
"webpack": "^5.0.0"
|
|
72
|
+
},
|
|
73
|
+
"bugs": {
|
|
74
|
+
"url": "https://github.com/ohos-ports/ohos-ports/issues"
|
|
75
|
+
}
|
|
76
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# bundle-declarations-webpack-plugin
|
|
2
|
+

|
|
3
|
+
[](https://github.com/dominicbirch/bundle-declarations-webpack-plugin/actions/workflows/release.yml)
|
|
4
|
+
[](https://github.com/dominicbirch/bundle-declarations-webpack-plugin/actions/workflows/test.yml)
|
|
5
|
+
[](https://github.com/sindresorhus/xo)
|
|
6
|
+
## Example usage
|
|
7
|
+
### Simplest scenario
|
|
8
|
+
As of version 3.1.0, it's possible to omit the configuration overrides; when you do this, the plugin will fallback on `webpack`'s entrypoints and other defaults.
|
|
9
|
+
```typescript
|
|
10
|
+
import BundleDeclarationsWebpackPlugin from "bundle-declarations-webpack-plugin";
|
|
11
|
+
import { resolve } from "path";
|
|
12
|
+
import type { Configuration } from "webpack";
|
|
13
|
+
|
|
14
|
+
export default <Configuration> {
|
|
15
|
+
entry: "./src/main.ts",
|
|
16
|
+
output: {
|
|
17
|
+
filename: "index.js",
|
|
18
|
+
path: resolve("./dist"),
|
|
19
|
+
},
|
|
20
|
+
plugins: [
|
|
21
|
+
`...`,
|
|
22
|
+
new BundleDeclarationsWebpackPlugin(),
|
|
23
|
+
],
|
|
24
|
+
};
|
|
25
|
+
```
|
|
26
|
+
The configuration above adds the plugin with default options. All typescript included/imported by the `./src/main.ts` file is transpiled to `./dist/index.js` and all exported types for the bundle are added to the output directory with the default name `index.d.ts`.
|
|
27
|
+
Just to be clear, currently the output filename is defaulted to this value, but the key in `webpack`'s entry is not considered/applied if set as it is with the webpack bundle.
|
|
28
|
+
### Most common scenario
|
|
29
|
+
Usually you will want to include all types which are visible on the surface of a library, but the `entry` and `outFile` may not necessarily match with your webpack bundle.
|
|
30
|
+
```typescript
|
|
31
|
+
import BundleDeclarationsWebpackPlugin from "bundle-declarations-webpack-plugin";
|
|
32
|
+
import type { Configuration } from "webpack";
|
|
33
|
+
|
|
34
|
+
export default <Configuration> {
|
|
35
|
+
plugins: [
|
|
36
|
+
`...`,
|
|
37
|
+
new BundleDeclarationsWebpackPlugin({
|
|
38
|
+
entry: ["./src/index.ts", "./src/globals.ts"],
|
|
39
|
+
outFile: "main.d.ts",
|
|
40
|
+
}),
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
In the above example, the exports of `index.ts` and `globals.ts` are combined into webpack's output as `main.d.ts`.
|
|
45
|
+
### When you need control of `dts-bundle-generator`
|
|
46
|
+
```typescript
|
|
47
|
+
import BundleDeclarationsWebpackPlugin from "bundle-declarations-webpack-plugin";
|
|
48
|
+
import type { Configuration } from "webpack";
|
|
49
|
+
|
|
50
|
+
export default <Configuration> {
|
|
51
|
+
plugins: [
|
|
52
|
+
`...`,
|
|
53
|
+
new BundleDeclarationsWebpackPlugin({
|
|
54
|
+
entry: {
|
|
55
|
+
filePath: "./src/index.ts",
|
|
56
|
+
libraries: {
|
|
57
|
+
inlinedLibraries: [
|
|
58
|
+
"tsyringe",
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
output: {
|
|
62
|
+
sortNodes: false,
|
|
63
|
+
// dts-bundle-generator comments in output
|
|
64
|
+
noBanner: false,
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
outFile: "index.d.ts",
|
|
68
|
+
|
|
69
|
+
compilationOptions: {
|
|
70
|
+
followSymlinks: true,
|
|
71
|
+
preferredConfigPath: "./some/tsconfig.json",
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
// setting these will mean no post-processing
|
|
75
|
+
removeEmptyLines: false,
|
|
76
|
+
removeEmptyExports: false,
|
|
77
|
+
removeRelativeReExport: false,
|
|
78
|
+
}),
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
### Multiple entrypoints with different config
|
|
83
|
+
Assuming you want to combine into 1 .d.ts bundle, this can be achieved by providing an array of `EntryPointConfig`s to a single plugin instance's `entry` option.
|
|
84
|
+
### Multiple bundles
|
|
85
|
+
This is expected, it should be completely safe to use multiple instances of the plugin as part of `webpack`'s parallel builds; in fact the only thing stopping you from reusing the same instance is that the options are shared (which might be fine in some cases).
|
|
86
|
+
## Watch mode
|
|
87
|
+
As of version 4.0.0, .d.ts bundling runs as a background process while `webpack` is in watch mode; this means that it will no longer delay incremental builds, but consequently the declarations may become out of sync with the webpack compilations.
|
|
88
|
+
Also note that the plugin will output to the file system even when `shouldEmit` returns `false`.
|
package/README.md
DELETED