@opentray/webpack-plugin 0.1.0 → 0.10.3
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/dist/index.d.mts +60 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +77 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +2 -2
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { OpenTrayArtifactInput, OpenTrayPackageManifest, OpenTrayPackageResult, OpenTrayPackagingApp } from "@opentray/packaging";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
interface OpenTrayWebpackPluginOptions {
|
|
5
|
+
readonly app: OpenTrayPackagingApp;
|
|
6
|
+
readonly runtimeHost: OpenTrayArtifactInput;
|
|
7
|
+
readonly nativeArtifacts?: Readonly<Record<string, OpenTrayArtifactInput>>;
|
|
8
|
+
readonly companionAssets?: Readonly<Record<string, OpenTrayArtifactInput>>;
|
|
9
|
+
readonly entry?: string;
|
|
10
|
+
readonly manifestPath?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Explicit outDir override. When omitted, resolved from
|
|
13
|
+
* `compiler.options.output.path`.
|
|
14
|
+
*/
|
|
15
|
+
readonly outDir?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Explicit mode override. When omitted, resolved from
|
|
18
|
+
* `compiler.options.mode` or defaults to `production`.
|
|
19
|
+
*/
|
|
20
|
+
readonly mode?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Structural view of the webpack compiler options the adapter consumes. Only the
|
|
24
|
+
* staging-relevant fields are declared, so webpack never has to be imported.
|
|
25
|
+
*/
|
|
26
|
+
interface WebpackOutputLike {
|
|
27
|
+
readonly path?: string;
|
|
28
|
+
}
|
|
29
|
+
interface WebpackEntryStaticLike {
|
|
30
|
+
readonly main?: string | readonly string[];
|
|
31
|
+
}
|
|
32
|
+
type WebpackEntryLike = string | readonly string[] | Readonly<Record<string, unknown>>;
|
|
33
|
+
interface WebpackOptionsLike {
|
|
34
|
+
readonly mode?: string;
|
|
35
|
+
readonly output?: WebpackOutputLike;
|
|
36
|
+
readonly entry?: WebpackEntryLike | WebpackEntryStaticLike;
|
|
37
|
+
}
|
|
38
|
+
interface WebpackCompilationLike {
|
|
39
|
+
readonly options: WebpackOptionsLike;
|
|
40
|
+
}
|
|
41
|
+
interface WebpackTapableHook<T> {
|
|
42
|
+
tapAsync(name: string, callback: (value: T, callback: (error?: Error) => void) => void): void;
|
|
43
|
+
}
|
|
44
|
+
interface WebpackCompilerLike {
|
|
45
|
+
readonly options: WebpackOptionsLike;
|
|
46
|
+
readonly hooks: {
|
|
47
|
+
readonly afterEmit: WebpackTapableHook<WebpackCompilationLike>;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
interface OpenTrayWebpackPlugin {
|
|
51
|
+
readonly name: "OpenTrayWebpackPlugin";
|
|
52
|
+
apply(compiler: WebpackCompilerLike): void;
|
|
53
|
+
/** Returns the last staging result. Only populated after `afterEmit` runs. */
|
|
54
|
+
readonly getLastResult: () => OpenTrayPackageResult | undefined;
|
|
55
|
+
}
|
|
56
|
+
declare const openTrayWebpackPlugin: (options: OpenTrayWebpackPluginOptions) => OpenTrayWebpackPlugin;
|
|
57
|
+
declare const resolveWebpackEntry: (entry: WebpackEntryLike | WebpackEntryStaticLike | undefined) => string;
|
|
58
|
+
//#endregion
|
|
59
|
+
export { type OpenTrayPackageManifest, type OpenTrayPackageResult, OpenTrayWebpackPlugin, OpenTrayWebpackPluginOptions, WebpackCompilationLike, WebpackCompilerLike, WebpackEntryLike, WebpackEntryStaticLike, WebpackOptionsLike, WebpackOutputLike, WebpackTapableHook, openTrayWebpackPlugin, resolveWebpackEntry };
|
|
60
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;UAQiB,4BAAA;EAAA,SACN,GAAA,EAAK,oBAAA;EAAA,SACL,WAAA,EAAa,qBAAA;EAAA,SACb,eAAA,GAAkB,QAAA,CAAS,MAAA,SAAe,qBAAA;EAAA,SAC1C,eAAA,GAAkB,QAAA,CAAS,MAAA,SAAe,qBAAA;EAAA,SAC1C,KAAA;EAAA,SACA,YAAA;EAH0C;;;;EAAA,SAQ1C,MAAA;EAPkB;;;;EAAA,SAYlB,IAAA;AAAA;;;;;UAOM,iBAAA;EAAA,SACN,IAAI;AAAA;AAAA,UAGE,sBAAA;EAAA,SACN,IAAI;AAAA;AAAA,KAGH,gBAAA,gCAAgD,QAAQ,CAAC,MAAA;AAAA,UAEpD,kBAAA;EAAA,SACN,IAAA;EAAA,SACA,MAAA,GAAS,iBAAA;EAAA,SACT,KAAA,GAAQ,gBAAA,GAAmB,sBAAA;AAAA;AAAA,UAGrB,sBAAA;EAAA,SACN,OAAA,EAAS,kBAAkB;AAAA;AAAA,UAGrB,kBAAA;EACf,QAAA,CACE,IAAA,UACA,QAAA,GAAW,KAAA,EAAO,CAAA,EAAG,QAAA,GAAW,KAAA,GAAQ,KAAK;AAAA;AAAA,UAIhC,mBAAA;EAAA,SACN,OAAA,EAAS,kBAAA;EAAA,SACT,KAAA;IAAA,SACE,SAAA,EAAW,kBAAA,CAAmB,sBAAA;EAAA;AAAA;AAAA,UAI1B,qBAAA;EAAA,SACN,IAAA;EACT,KAAA,CAAM,QAAA,EAAU,mBAAA;EA1BiB;EAAA,SA4BxB,aAAA,QAAqB,qBAAqB;AAAA;AAAA,cAGxC,qBAAA,GACX,OAAA,EAAS,4BAAA,KACR,qBAgCF;AAAA,cAqBY,mBAAA,GACX,KAAA,EAAO,gBAAA,GAAmB,sBAAsB"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { stageOpenTrayPackage } from "@opentray/packaging";
|
|
2
|
+
//#region src/index.ts
|
|
3
|
+
const openTrayWebpackPlugin = (options) => {
|
|
4
|
+
let lastResult;
|
|
5
|
+
return {
|
|
6
|
+
name: "OpenTrayWebpackPlugin",
|
|
7
|
+
apply(compiler) {
|
|
8
|
+
compiler.hooks.afterEmit.tapAsync("OpenTrayWebpackPlugin", async (_compilation, cb) => {
|
|
9
|
+
try {
|
|
10
|
+
lastResult = await stageOpenTrayPackage({
|
|
11
|
+
app: options.app,
|
|
12
|
+
outDir: resolveWebpackOutDir(options, compiler.options),
|
|
13
|
+
entry: options.entry ?? resolveWebpackEntry(compiler.options.entry),
|
|
14
|
+
adapter: {
|
|
15
|
+
name: "webpack",
|
|
16
|
+
mode: resolveWebpackMode(options, compiler.options)
|
|
17
|
+
},
|
|
18
|
+
runtimeHost: options.runtimeHost,
|
|
19
|
+
...options.nativeArtifacts === void 0 ? {} : { nativeArtifacts: options.nativeArtifacts },
|
|
20
|
+
...options.companionAssets === void 0 ? {} : { companionAssets: options.companionAssets },
|
|
21
|
+
...options.manifestPath === void 0 ? {} : { manifestPath: options.manifestPath }
|
|
22
|
+
});
|
|
23
|
+
cb();
|
|
24
|
+
} catch (error) {
|
|
25
|
+
cb(error);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
getLastResult: () => lastResult
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
const resolveWebpackOutDir = (options, compilerOptions) => {
|
|
33
|
+
if (options.outDir !== void 0) return options.outDir;
|
|
34
|
+
const outputDir = compilerOptions.output?.path;
|
|
35
|
+
if (outputDir !== void 0 && outputDir.length > 0) return outputDir;
|
|
36
|
+
return process.cwd();
|
|
37
|
+
};
|
|
38
|
+
const resolveWebpackMode = (options, compilerOptions) => options.mode ?? compilerOptions.mode ?? "production";
|
|
39
|
+
const resolveWebpackEntry = (entry) => {
|
|
40
|
+
const missing = () => /* @__PURE__ */ new Error("OpenTray webpack packaging requires a webpack entry or an explicit entry option");
|
|
41
|
+
if (entry === void 0) throw missing();
|
|
42
|
+
const fromValue = (value) => {
|
|
43
|
+
if (typeof value === "string") return value.length > 0 ? value : void 0;
|
|
44
|
+
if (Array.isArray(value)) {
|
|
45
|
+
const first = value[0];
|
|
46
|
+
return typeof first === "string" && first.length > 0 ? first : void 0;
|
|
47
|
+
}
|
|
48
|
+
if (value !== null && typeof value === "object") {
|
|
49
|
+
const importValue = value.import;
|
|
50
|
+
const fromImport = fromValue(importValue);
|
|
51
|
+
if (fromImport !== void 0) return fromImport;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
if (typeof entry === "string") {
|
|
55
|
+
if (entry.length === 0) throw missing();
|
|
56
|
+
return entry;
|
|
57
|
+
}
|
|
58
|
+
if (Array.isArray(entry)) {
|
|
59
|
+
const first = fromValue(entry);
|
|
60
|
+
if (first === void 0) throw missing();
|
|
61
|
+
return first;
|
|
62
|
+
}
|
|
63
|
+
if (typeof entry === "object") {
|
|
64
|
+
const record = entry;
|
|
65
|
+
const mainValue = record.main;
|
|
66
|
+
const fromMain = fromValue(mainValue);
|
|
67
|
+
if (fromMain !== void 0) return fromMain;
|
|
68
|
+
const firstValue = Object.values(record)[0];
|
|
69
|
+
const fromFirst = fromValue(firstValue);
|
|
70
|
+
if (fromFirst !== void 0) return fromFirst;
|
|
71
|
+
}
|
|
72
|
+
throw missing();
|
|
73
|
+
};
|
|
74
|
+
//#endregion
|
|
75
|
+
export { openTrayWebpackPlugin, resolveWebpackEntry };
|
|
76
|
+
|
|
77
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["record"],"sources":["../src/index.ts"],"sourcesContent":["import {\n stageOpenTrayPackage,\n type OpenTrayArtifactInput,\n type OpenTrayPackagingApp,\n type OpenTrayPackageManifest,\n type OpenTrayPackageResult,\n} from \"@opentray/packaging\";\n\nexport interface OpenTrayWebpackPluginOptions {\n readonly app: OpenTrayPackagingApp;\n readonly runtimeHost: OpenTrayArtifactInput;\n readonly nativeArtifacts?: Readonly<Record<string, OpenTrayArtifactInput>>;\n readonly companionAssets?: Readonly<Record<string, OpenTrayArtifactInput>>;\n readonly entry?: string;\n readonly manifestPath?: string;\n /**\n * Explicit outDir override. When omitted, resolved from\n * `compiler.options.output.path`.\n */\n readonly outDir?: string;\n /**\n * Explicit mode override. When omitted, resolved from\n * `compiler.options.mode` or defaults to `production`.\n */\n readonly mode?: string;\n}\n\n/**\n * Structural view of the webpack compiler options the adapter consumes. Only the\n * staging-relevant fields are declared, so webpack never has to be imported.\n */\nexport interface WebpackOutputLike {\n readonly path?: string;\n}\n\nexport interface WebpackEntryStaticLike {\n readonly main?: string | readonly string[];\n}\n\nexport type WebpackEntryLike = string | readonly string[] | Readonly<Record<string, unknown>>;\n\nexport interface WebpackOptionsLike {\n readonly mode?: string;\n readonly output?: WebpackOutputLike;\n readonly entry?: WebpackEntryLike | WebpackEntryStaticLike;\n}\n\nexport interface WebpackCompilationLike {\n readonly options: WebpackOptionsLike;\n}\n\nexport interface WebpackTapableHook<T> {\n tapAsync(\n name: string,\n callback: (value: T, callback: (error?: Error) => void) => void,\n ): void;\n}\n\nexport interface WebpackCompilerLike {\n readonly options: WebpackOptionsLike;\n readonly hooks: {\n readonly afterEmit: WebpackTapableHook<WebpackCompilationLike>;\n };\n}\n\nexport interface OpenTrayWebpackPlugin {\n readonly name: \"OpenTrayWebpackPlugin\";\n apply(compiler: WebpackCompilerLike): void;\n /** Returns the last staging result. Only populated after `afterEmit` runs. */\n readonly getLastResult: () => OpenTrayPackageResult | undefined;\n}\n\nexport const openTrayWebpackPlugin = (\n options: OpenTrayWebpackPluginOptions,\n): OpenTrayWebpackPlugin => {\n let lastResult: OpenTrayPackageResult | undefined;\n\n return {\n name: \"OpenTrayWebpackPlugin\",\n apply(compiler) {\n compiler.hooks.afterEmit.tapAsync(\"OpenTrayWebpackPlugin\", async (_compilation, cb) => {\n try {\n lastResult = await stageOpenTrayPackage({\n app: options.app,\n outDir: resolveWebpackOutDir(options, compiler.options),\n entry: options.entry ?? resolveWebpackEntry(compiler.options.entry),\n adapter: { name: \"webpack\", mode: resolveWebpackMode(options, compiler.options) },\n runtimeHost: options.runtimeHost,\n ...(options.nativeArtifacts === undefined\n ? {}\n : { nativeArtifacts: options.nativeArtifacts }),\n ...(options.companionAssets === undefined\n ? {}\n : { companionAssets: options.companionAssets }),\n ...(options.manifestPath === undefined\n ? {}\n : { manifestPath: options.manifestPath }),\n });\n cb();\n } catch (error) {\n cb(error as Error);\n }\n });\n },\n getLastResult: () => lastResult,\n };\n};\n\nconst resolveWebpackOutDir = (\n options: OpenTrayWebpackPluginOptions,\n compilerOptions: WebpackOptionsLike,\n): string => {\n if (options.outDir !== undefined) {\n return options.outDir;\n }\n const outputDir = compilerOptions.output?.path;\n if (outputDir !== undefined && outputDir.length > 0) {\n return outputDir;\n }\n return process.cwd();\n};\n\nconst resolveWebpackMode = (\n options: OpenTrayWebpackPluginOptions,\n compilerOptions: WebpackOptionsLike,\n): string => options.mode ?? compilerOptions.mode ?? \"production\";\n\nexport const resolveWebpackEntry = (\n entry: WebpackEntryLike | WebpackEntryStaticLike | undefined,\n): string => {\n const missing = () =>\n new Error(\n \"OpenTray webpack packaging requires a webpack entry or an explicit entry option\",\n );\n if (entry === undefined) {\n throw missing();\n }\n const fromValue = (value: unknown): string | undefined => {\n if (typeof value === \"string\") {\n return value.length > 0 ? value : undefined;\n }\n if (Array.isArray(value)) {\n const first = value[0];\n return typeof first === \"string\" && first.length > 0 ? first : undefined;\n }\n if (value !== null && typeof value === \"object\") {\n const record = value as Readonly<Record<string, unknown>>;\n const importValue = record.import;\n const fromImport = fromValue(importValue);\n if (fromImport !== undefined) {\n return fromImport;\n }\n }\n return undefined;\n };\n if (typeof entry === \"string\") {\n if (entry.length === 0) {\n throw missing();\n }\n return entry;\n }\n if (Array.isArray(entry)) {\n const first = fromValue(entry);\n if (first === undefined) {\n throw missing();\n }\n return first;\n }\n if (typeof entry === \"object\") {\n const record = entry as Readonly<Record<string, unknown>>;\n const mainValue = record.main;\n const fromMain = fromValue(mainValue);\n if (fromMain !== undefined) {\n return fromMain;\n }\n const firstValue = Object.values(record)[0];\n const fromFirst = fromValue(firstValue);\n if (fromFirst !== undefined) {\n return fromFirst;\n }\n }\n throw missing();\n};\n\nexport type { OpenTrayPackageManifest, OpenTrayPackageResult };\n"],"mappings":";;AAwEA,MAAa,yBACX,YAC0B;CAC1B,IAAI;CAEJ,OAAO;EACL,MAAM;EACN,MAAM,UAAU;GACd,SAAS,MAAM,UAAU,SAAS,yBAAyB,OAAO,cAAc,OAAO;IACrF,IAAI;KACF,aAAa,MAAM,qBAAqB;MACtC,KAAK,QAAQ;MACb,QAAQ,qBAAqB,SAAS,SAAS,OAAO;MACtD,OAAO,QAAQ,SAAS,oBAAoB,SAAS,QAAQ,KAAK;MAClE,SAAS;OAAE,MAAM;OAAW,MAAM,mBAAmB,SAAS,SAAS,OAAO;MAAE;MAChF,aAAa,QAAQ;MACrB,GAAI,QAAQ,oBAAoB,KAAA,IAC5B,CAAC,IACD,EAAE,iBAAiB,QAAQ,gBAAgB;MAC/C,GAAI,QAAQ,oBAAoB,KAAA,IAC5B,CAAC,IACD,EAAE,iBAAiB,QAAQ,gBAAgB;MAC/C,GAAI,QAAQ,iBAAiB,KAAA,IACzB,CAAC,IACD,EAAE,cAAc,QAAQ,aAAa;KAC3C,CAAC;KACD,GAAG;IACL,SAAS,OAAO;KACd,GAAG,KAAc;IACnB;GACF,CAAC;EACH;EACA,qBAAqB;CACvB;AACF;AAEA,MAAM,wBACJ,SACA,oBACW;CACX,IAAI,QAAQ,WAAW,KAAA,GACrB,OAAO,QAAQ;CAEjB,MAAM,YAAY,gBAAgB,QAAQ;CAC1C,IAAI,cAAc,KAAA,KAAa,UAAU,SAAS,GAChD,OAAO;CAET,OAAO,QAAQ,IAAI;AACrB;AAEA,MAAM,sBACJ,SACA,oBACW,QAAQ,QAAQ,gBAAgB,QAAQ;AAErD,MAAa,uBACX,UACW;CACX,MAAM,gCACJ,IAAI,MACF,iFACF;CACF,IAAI,UAAU,KAAA,GACZ,MAAM,QAAQ;CAEhB,MAAM,aAAa,UAAuC;EACxD,IAAI,OAAO,UAAU,UACnB,OAAO,MAAM,SAAS,IAAI,QAAQ,KAAA;EAEpC,IAAI,MAAM,QAAQ,KAAK,GAAG;GACxB,MAAM,QAAQ,MAAM;GACpB,OAAO,OAAO,UAAU,YAAY,MAAM,SAAS,IAAI,QAAQ,KAAA;EACjE;EACA,IAAI,UAAU,QAAQ,OAAO,UAAU,UAAU;GAE/C,MAAM,cAAcA,MAAO;GAC3B,MAAM,aAAa,UAAU,WAAW;GACxC,IAAI,eAAe,KAAA,GACjB,OAAO;EAEX;CAEF;CACA,IAAI,OAAO,UAAU,UAAU;EAC7B,IAAI,MAAM,WAAW,GACnB,MAAM,QAAQ;EAEhB,OAAO;CACT;CACA,IAAI,MAAM,QAAQ,KAAK,GAAG;EACxB,MAAM,QAAQ,UAAU,KAAK;EAC7B,IAAI,UAAU,KAAA,GACZ,MAAM,QAAQ;EAEhB,OAAO;CACT;CACA,IAAI,OAAO,UAAU,UAAU;EAC7B,MAAM,SAAS;EACf,MAAM,YAAY,OAAO;EACzB,MAAM,WAAW,UAAU,SAAS;EACpC,IAAI,aAAa,KAAA,GACf,OAAO;EAET,MAAM,aAAa,OAAO,OAAO,MAAM,EAAE;EACzC,MAAM,YAAY,UAAU,UAAU;EACtC,IAAI,cAAc,KAAA,GAChB,OAAO;CAEX;CACA,MAAM,QAAQ;AAChB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentray/webpack-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.3",
|
|
4
4
|
"description": "webpack adapter for the OpenTray runtime artifact packaging contract.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
],
|
|
22
22
|
"sideEffects": false,
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@opentray/packaging": "0.
|
|
24
|
+
"@opentray/packaging": "0.10.3"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"webpack": ">=5"
|