@componentonce/compiler-esbuild 0.1.0-beta.0
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/README.md +31 -0
- package/dist/index.d.ts +137 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +290 -0
- package/dist/index.js.map +1 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
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/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# @componentonce/compiler-esbuild
|
|
2
|
+
|
|
3
|
+
Optional trusted compiler/evaluator tooling for ComponentOnce.
|
|
4
|
+
|
|
5
|
+
This package is not part of the core runtime ABI and owns no storage or transport.
|
|
6
|
+
|
|
7
|
+
## Generic modules
|
|
8
|
+
|
|
9
|
+
compileTrustedModule compiles JavaScript/TypeScript into an immutable CommonJS artifact. It adds no runtime externals implicitly. Any imported host module must be declared explicitly through externalModules and injected when instantiateTrustedBundle executes the trusted artifact.
|
|
10
|
+
|
|
11
|
+
This is suitable for ordinary DOM/HTML modules and other non-React implementations.
|
|
12
|
+
|
|
13
|
+
## React convenience
|
|
14
|
+
|
|
15
|
+
compileTrustedReactModule wraps the generic compiler with automatic JSX transformation and allows the React module specifiers as host externals:
|
|
16
|
+
|
|
17
|
+
- react
|
|
18
|
+
- react/jsx-runtime
|
|
19
|
+
- react/jsx-dev-runtime
|
|
20
|
+
|
|
21
|
+
React is still never bundled. The host injects its own React singleton at instantiation. Additional host SDK imports use additionalExternalModules.
|
|
22
|
+
|
|
23
|
+
## Artifact and trust model
|
|
24
|
+
|
|
25
|
+
Artifacts contain deterministic bundle text, byte length, SHA-256 hash/integrity, normalized diagnostics, exact referenced externals, and esbuild metafile data.
|
|
26
|
+
|
|
27
|
+
instantiateTrustedBundle deliberately uses new Function with a narrow injected require map. It is for trusted internal code and is not a security sandbox.
|
|
28
|
+
|
|
29
|
+
Storage is host-owned: compiled text/bytes can live in a database-backed file object, local disk, object storage, or any other adapter.
|
|
30
|
+
|
|
31
|
+
esbuild transpiles TypeScript syntax but does not perform semantic type checking; hosts that need that guarantee should run their TypeScript checker separately.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { type Metafile } from "esbuild";
|
|
2
|
+
/** Stable identifier for the trusted CommonJS bundle contract emitted by this package. */
|
|
3
|
+
export declare const COMPONENTONCE_TRUSTED_BUNDLE_FORMAT: "componentonce.trusted-cjs.v1";
|
|
4
|
+
/** Source syntaxes accepted by the trusted compiler. */
|
|
5
|
+
export type ComponentOnceSourceLoader = "js" | "jsx" | "ts" | "tsx";
|
|
6
|
+
/** JSX transform mode forwarded to esbuild by the generic compiler. */
|
|
7
|
+
export type ComponentOnceJsxMode = "transform" | "preserve" | "automatic";
|
|
8
|
+
/** Input for compiling one trusted JavaScript or TypeScript module. */
|
|
9
|
+
export interface ComponentOnceCompileInput {
|
|
10
|
+
/** TypeScript, TSX, JavaScript, or JSX module source. */
|
|
11
|
+
readonly source: string;
|
|
12
|
+
/** Stable diagnostic/source-map name. */
|
|
13
|
+
readonly sourceFileName?: string;
|
|
14
|
+
/** Explicit source syntax, otherwise inferred from sourceFileName. */
|
|
15
|
+
readonly loader?: ComponentOnceSourceLoader;
|
|
16
|
+
/** Exact import specifiers the host will inject during instantiation. */
|
|
17
|
+
readonly externalModules?: readonly string[];
|
|
18
|
+
/** JSX transform mode; generic compilation defaults to transform. */
|
|
19
|
+
readonly jsx?: ComponentOnceJsxMode;
|
|
20
|
+
}
|
|
21
|
+
/** React convenience compiler input; React externals are supplied by the wrapper. */
|
|
22
|
+
export interface ComponentOnceReactCompileInput {
|
|
23
|
+
readonly source: string;
|
|
24
|
+
readonly sourceFileName?: string;
|
|
25
|
+
readonly loader?: ComponentOnceSourceLoader;
|
|
26
|
+
/** Additional non-React host externals. */
|
|
27
|
+
readonly additionalExternalModules?: readonly string[];
|
|
28
|
+
}
|
|
29
|
+
/** Source location attached to a normalized compiler diagnostic. */
|
|
30
|
+
export interface ComponentOnceDiagnosticLocation {
|
|
31
|
+
/** Source file name supplied to the compiler. */
|
|
32
|
+
readonly file: string;
|
|
33
|
+
/** One-based source line. */
|
|
34
|
+
readonly line: number;
|
|
35
|
+
/** Zero-based source column. */
|
|
36
|
+
readonly column: number;
|
|
37
|
+
/** Length of the highlighted source range. */
|
|
38
|
+
readonly length: number;
|
|
39
|
+
/** Full source line associated with the diagnostic. */
|
|
40
|
+
readonly lineText: string;
|
|
41
|
+
}
|
|
42
|
+
/** Secondary explanatory note attached to a compiler diagnostic. */
|
|
43
|
+
export interface ComponentOnceDiagnosticNote {
|
|
44
|
+
/** Human-readable note. */
|
|
45
|
+
readonly text: string;
|
|
46
|
+
/** Source location when esbuild can identify one. */
|
|
47
|
+
readonly location?: ComponentOnceDiagnosticLocation;
|
|
48
|
+
}
|
|
49
|
+
/** Storage-neutral compiler warning or error. */
|
|
50
|
+
export interface ComponentOnceDiagnostic {
|
|
51
|
+
/** Diagnostic severity. */
|
|
52
|
+
readonly kind: "error" | "warning";
|
|
53
|
+
/** Human-readable diagnostic text. */
|
|
54
|
+
readonly text: string;
|
|
55
|
+
/** Primary source location when available. */
|
|
56
|
+
readonly location?: ComponentOnceDiagnosticLocation;
|
|
57
|
+
/** Supporting notes supplied by esbuild. */
|
|
58
|
+
readonly notes: readonly ComponentOnceDiagnosticNote[];
|
|
59
|
+
}
|
|
60
|
+
/** Read-only esbuild metadata describing the emitted bundle and its external imports. */
|
|
61
|
+
export type ComponentOnceBundleMetafile = Readonly<Metafile>;
|
|
62
|
+
/** Immutable, storage-neutral output of the trusted module compiler. */
|
|
63
|
+
export interface ComponentOnceTrustedBundleArtifact {
|
|
64
|
+
/** Bundle contract understood by `instantiateTrustedBundle`. */
|
|
65
|
+
readonly format: typeof COMPONENTONCE_TRUSTED_BUNDLE_FORMAT;
|
|
66
|
+
/** Executable CommonJS bundle text. */
|
|
67
|
+
readonly code: string;
|
|
68
|
+
/** UTF-8 byte length of `code`. */
|
|
69
|
+
readonly byteLength: number;
|
|
70
|
+
/** Lowercase hexadecimal SHA-256 digest of `code`. */
|
|
71
|
+
readonly sha256: string;
|
|
72
|
+
/** Subresource-integrity-style SHA-256 value for `code`. */
|
|
73
|
+
readonly integrity: string;
|
|
74
|
+
/** Exact external module specifiers referenced by the emitted bundle. */
|
|
75
|
+
readonly externalModules: readonly string[];
|
|
76
|
+
/** Normalized non-fatal compiler diagnostics. */
|
|
77
|
+
readonly diagnostics: readonly ComponentOnceDiagnostic[];
|
|
78
|
+
/** esbuild metadata for dependency and output inspection. */
|
|
79
|
+
readonly metafile: ComponentOnceBundleMetafile;
|
|
80
|
+
}
|
|
81
|
+
/** Compilation failure with stable, normalized esbuild diagnostics. */
|
|
82
|
+
export declare class ComponentOnceCompileError extends Error {
|
|
83
|
+
/** Compiler errors that caused the build to fail. */
|
|
84
|
+
readonly diagnostics: readonly ComponentOnceDiagnostic[];
|
|
85
|
+
constructor(diagnostics: readonly ComponentOnceDiagnostic[]);
|
|
86
|
+
}
|
|
87
|
+
/** Exact host-owned module values exposed to a trusted bundle's local `require`. */
|
|
88
|
+
export type ComponentOnceHostExternals = Readonly<Record<string, unknown>>;
|
|
89
|
+
/** JavaScript text, UTF-8 bytes, or an in-memory artifact accepted by the trusted evaluator. */
|
|
90
|
+
export type ComponentOnceTrustedBundleSource = string | Uint8Array | ComponentOnceTrustedBundleArtifact;
|
|
91
|
+
/** Options controlling explicit external injection and optional integrity verification. */
|
|
92
|
+
export interface InstantiateTrustedBundleOptions {
|
|
93
|
+
/** Exact external values, including the host's React and JSX runtime instances. */
|
|
94
|
+
readonly externals: ComponentOnceHostExternals;
|
|
95
|
+
/** Expected integrity for separately loaded text/bytes; artifacts verify their own value by default. */
|
|
96
|
+
readonly expectedIntegrity?: string;
|
|
97
|
+
/** Debugger-only source name appended to the evaluated bundle. */
|
|
98
|
+
readonly sourceName?: string;
|
|
99
|
+
}
|
|
100
|
+
/** Deterministic error raised when a bundle requests an external the host did not inject. */
|
|
101
|
+
export declare class ComponentOnceMissingExternalError extends Error {
|
|
102
|
+
/** Exact module specifier requested by the bundle. */
|
|
103
|
+
readonly specifier: string;
|
|
104
|
+
/** Sorted external specifiers supplied by the host. */
|
|
105
|
+
readonly availableExternals: readonly string[];
|
|
106
|
+
constructor(specifier: string, availableExternals: readonly string[]);
|
|
107
|
+
}
|
|
108
|
+
/** Error raised when loaded bundle content does not match its expected SHA-256 integrity. */
|
|
109
|
+
export declare class ComponentOnceIntegrityError extends Error {
|
|
110
|
+
/** Expected subresource-integrity-style SHA-256 value. */
|
|
111
|
+
readonly expectedIntegrity: string;
|
|
112
|
+
/** Actual subresource-integrity-style SHA-256 value. */
|
|
113
|
+
readonly actualIntegrity: string;
|
|
114
|
+
constructor(expectedIntegrity: string, actualIntegrity: string);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Compile one trusted module into a deterministic CommonJS artifact.
|
|
118
|
+
*
|
|
119
|
+
* Only caller-declared imports remain external. This generic path does not add React or any other
|
|
120
|
+
* runtime implicitly; every external must be injected explicitly by the host at instantiation.
|
|
121
|
+
*/
|
|
122
|
+
export declare function compileTrustedModule(input: ComponentOnceCompileInput): Promise<ComponentOnceTrustedBundleArtifact>;
|
|
123
|
+
/** Compile a trusted React module while keeping the host React singleton external. */
|
|
124
|
+
export declare function compileTrustedReactModule(input: ComponentOnceReactCompileInput): Promise<ComponentOnceTrustedBundleArtifact>;
|
|
125
|
+
/** Calculate a subresource-integrity-style SHA-256 value for bundle text or UTF-8 bytes. */
|
|
126
|
+
export declare function calculateTrustedBundleIntegrity(source: string | Uint8Array): string;
|
|
127
|
+
/** Throw when bundle text or bytes do not match an expected SHA-256 integrity value. */
|
|
128
|
+
export declare function assertTrustedBundleIntegrity(source: string | Uint8Array, expectedIntegrity: string): void;
|
|
129
|
+
/**
|
|
130
|
+
* Execute a trusted bundle with a deliberately narrow CommonJS environment.
|
|
131
|
+
*
|
|
132
|
+
* This API uses `new Function` and is only for trusted internal code. It is not a sandbox: evaluated
|
|
133
|
+
* code retains access to JavaScript globals. The only available `require` values are provided by
|
|
134
|
+
* `options.externals`, so React is always the exact instance selected by the host.
|
|
135
|
+
*/
|
|
136
|
+
export declare function instantiateTrustedBundle<TExports = Record<string, unknown>>(source: ComponentOnceTrustedBundleSource, options: InstantiateTrustedBundleOptions): TExports;
|
|
137
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,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CAW7C;AAED,4FAA4F;AAC5F,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,CAEnF;AAED,wFAAwF;AACxF,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,MAAM,GAAG,UAAU,EAC3B,iBAAiB,EAAE,MAAM,GACxB,IAAI,CAKN;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzE,MAAM,EAAE,gCAAgC,EACxC,OAAO,EAAE,+BAA+B,GACvC,QAAQ,CAiCV"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { build, } from "esbuild";
|
|
3
|
+
/** Stable identifier for the trusted CommonJS bundle contract emitted by this package. */
|
|
4
|
+
export const COMPONENTONCE_TRUSTED_BUNDLE_FORMAT = "componentonce.trusted-cjs.v1";
|
|
5
|
+
const DEFAULT_SOURCE_FILE_NAME = "componentonce-module.ts";
|
|
6
|
+
const DEFAULT_REACT_SOURCE_FILE_NAME = "componentonce-module.tsx";
|
|
7
|
+
const DEFAULT_EVALUATED_SOURCE_NAME = "componentonce-trusted-bundle.js";
|
|
8
|
+
const REACT_EXTERNALS = ["react", "react/jsx-runtime", "react/jsx-dev-runtime"];
|
|
9
|
+
/** Compilation failure with stable, normalized esbuild diagnostics. */
|
|
10
|
+
export class ComponentOnceCompileError extends Error {
|
|
11
|
+
/** Compiler errors that caused the build to fail. */
|
|
12
|
+
diagnostics;
|
|
13
|
+
constructor(diagnostics) {
|
|
14
|
+
super(formatCompileErrorMessage(diagnostics));
|
|
15
|
+
this.name = "ComponentOnceCompileError";
|
|
16
|
+
this.diagnostics = Object.freeze([...diagnostics]);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** Deterministic error raised when a bundle requests an external the host did not inject. */
|
|
20
|
+
export class ComponentOnceMissingExternalError extends Error {
|
|
21
|
+
/** Exact module specifier requested by the bundle. */
|
|
22
|
+
specifier;
|
|
23
|
+
/** Sorted external specifiers supplied by the host. */
|
|
24
|
+
availableExternals;
|
|
25
|
+
constructor(specifier, availableExternals) {
|
|
26
|
+
const sortedExternals = Object.freeze([...availableExternals].sort());
|
|
27
|
+
const available = sortedExternals.length === 0 ? "(none)" : sortedExternals.join(", ");
|
|
28
|
+
super(`Missing trusted bundle external "${specifier}". Available externals: ${available}.`);
|
|
29
|
+
this.name = "ComponentOnceMissingExternalError";
|
|
30
|
+
this.specifier = specifier;
|
|
31
|
+
this.availableExternals = sortedExternals;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** Error raised when loaded bundle content does not match its expected SHA-256 integrity. */
|
|
35
|
+
export class ComponentOnceIntegrityError extends Error {
|
|
36
|
+
/** Expected subresource-integrity-style SHA-256 value. */
|
|
37
|
+
expectedIntegrity;
|
|
38
|
+
/** Actual subresource-integrity-style SHA-256 value. */
|
|
39
|
+
actualIntegrity;
|
|
40
|
+
constructor(expectedIntegrity, actualIntegrity) {
|
|
41
|
+
super(`Trusted bundle integrity mismatch. Expected "${expectedIntegrity}" but received "${actualIntegrity}".`);
|
|
42
|
+
this.name = "ComponentOnceIntegrityError";
|
|
43
|
+
this.expectedIntegrity = expectedIntegrity;
|
|
44
|
+
this.actualIntegrity = actualIntegrity;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Compile one trusted module into a deterministic CommonJS artifact.
|
|
49
|
+
*
|
|
50
|
+
* Only caller-declared imports remain external. This generic path does not add React or any other
|
|
51
|
+
* runtime implicitly; every external must be injected explicitly by the host at instantiation.
|
|
52
|
+
*/
|
|
53
|
+
export async function compileTrustedModule(input) {
|
|
54
|
+
const sourceFileName = input.sourceFileName ?? DEFAULT_SOURCE_FILE_NAME;
|
|
55
|
+
const loader = input.loader ?? inferLoader(sourceFileName);
|
|
56
|
+
const allowedExternals = normalizeAllowedExternals(input.externalModules ?? []);
|
|
57
|
+
try {
|
|
58
|
+
const result = await build({
|
|
59
|
+
bundle: true,
|
|
60
|
+
charset: "utf8",
|
|
61
|
+
format: "cjs",
|
|
62
|
+
jsx: input.jsx ?? "transform",
|
|
63
|
+
legalComments: "none",
|
|
64
|
+
logLevel: "silent",
|
|
65
|
+
metafile: true,
|
|
66
|
+
minify: false,
|
|
67
|
+
platform: "neutral",
|
|
68
|
+
plugins: [createHostExternalPlugin(allowedExternals)],
|
|
69
|
+
sourcemap: "inline",
|
|
70
|
+
sourcesContent: true,
|
|
71
|
+
stdin: {
|
|
72
|
+
contents: input.source,
|
|
73
|
+
loader: loader,
|
|
74
|
+
sourcefile: sourceFileName,
|
|
75
|
+
},
|
|
76
|
+
target: "es2022",
|
|
77
|
+
treeShaking: true,
|
|
78
|
+
write: false,
|
|
79
|
+
});
|
|
80
|
+
const output = result.outputFiles?.[0];
|
|
81
|
+
if (output === undefined || result.metafile === undefined) {
|
|
82
|
+
throw new ComponentOnceCompileError([
|
|
83
|
+
createInternalDiagnostic("esbuild did not return an in-memory bundle and metafile."),
|
|
84
|
+
]);
|
|
85
|
+
}
|
|
86
|
+
const code = output.text;
|
|
87
|
+
const hashes = hashBundleSource(code);
|
|
88
|
+
const metafile = deepFreeze(result.metafile);
|
|
89
|
+
const diagnostics = Object.freeze(result.warnings.map((warning) => normalizeMessage("warning", warning)));
|
|
90
|
+
const externalModules = Object.freeze(collectExternalModules(metafile));
|
|
91
|
+
return Object.freeze({
|
|
92
|
+
format: COMPONENTONCE_TRUSTED_BUNDLE_FORMAT,
|
|
93
|
+
code,
|
|
94
|
+
byteLength: hashes.byteLength,
|
|
95
|
+
sha256: hashes.sha256,
|
|
96
|
+
integrity: hashes.integrity,
|
|
97
|
+
externalModules,
|
|
98
|
+
diagnostics,
|
|
99
|
+
metafile,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
if (error instanceof ComponentOnceCompileError)
|
|
104
|
+
throw error;
|
|
105
|
+
if (isBuildFailure(error)) {
|
|
106
|
+
throw new ComponentOnceCompileError(error.errors.map((message) => normalizeMessage("error", message)));
|
|
107
|
+
}
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/** Compile a trusted React module while keeping the host React singleton external. */
|
|
112
|
+
export function compileTrustedReactModule(input) {
|
|
113
|
+
return compileTrustedModule({
|
|
114
|
+
source: input.source,
|
|
115
|
+
sourceFileName: input.sourceFileName ?? DEFAULT_REACT_SOURCE_FILE_NAME,
|
|
116
|
+
...(input.loader === undefined ? {} : { loader: input.loader }),
|
|
117
|
+
externalModules: [
|
|
118
|
+
...REACT_EXTERNALS,
|
|
119
|
+
...(input.additionalExternalModules ?? []),
|
|
120
|
+
],
|
|
121
|
+
jsx: "automatic",
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
/** Calculate a subresource-integrity-style SHA-256 value for bundle text or UTF-8 bytes. */
|
|
125
|
+
export function calculateTrustedBundleIntegrity(source) {
|
|
126
|
+
return hashBundleSource(source).integrity;
|
|
127
|
+
}
|
|
128
|
+
/** Throw when bundle text or bytes do not match an expected SHA-256 integrity value. */
|
|
129
|
+
export function assertTrustedBundleIntegrity(source, expectedIntegrity) {
|
|
130
|
+
const actualIntegrity = calculateTrustedBundleIntegrity(source);
|
|
131
|
+
if (actualIntegrity !== expectedIntegrity) {
|
|
132
|
+
throw new ComponentOnceIntegrityError(expectedIntegrity, actualIntegrity);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Execute a trusted bundle with a deliberately narrow CommonJS environment.
|
|
137
|
+
*
|
|
138
|
+
* This API uses `new Function` and is only for trusted internal code. It is not a sandbox: evaluated
|
|
139
|
+
* code retains access to JavaScript globals. The only available `require` values are provided by
|
|
140
|
+
* `options.externals`, so React is always the exact instance selected by the host.
|
|
141
|
+
*/
|
|
142
|
+
export function instantiateTrustedBundle(source, options) {
|
|
143
|
+
const artifact = isBundleArtifact(source) ? source : undefined;
|
|
144
|
+
if (artifact !== undefined && artifact.format !== COMPONENTONCE_TRUSTED_BUNDLE_FORMAT) {
|
|
145
|
+
throw new TypeError(`Unsupported trusted bundle format: "${String(artifact.format)}".`);
|
|
146
|
+
}
|
|
147
|
+
const bundleSource = artifact === undefined ? source : artifact.code;
|
|
148
|
+
const expectedIntegrity = options.expectedIntegrity ?? artifact?.integrity;
|
|
149
|
+
if (expectedIntegrity !== undefined) {
|
|
150
|
+
assertTrustedBundleIntegrity(bundleSource, expectedIntegrity);
|
|
151
|
+
}
|
|
152
|
+
const code = typeof bundleSource === "string" ? bundleSource : decodeUtf8(bundleSource);
|
|
153
|
+
const availableExternals = Object.keys(options.externals).sort();
|
|
154
|
+
const trustedRequire = (specifier) => {
|
|
155
|
+
if (!Object.prototype.hasOwnProperty.call(options.externals, specifier)) {
|
|
156
|
+
throw new ComponentOnceMissingExternalError(specifier, availableExternals);
|
|
157
|
+
}
|
|
158
|
+
return options.externals[specifier];
|
|
159
|
+
};
|
|
160
|
+
const commonJsModule = { exports: {} };
|
|
161
|
+
const sourceName = sanitizeSourceName(options.sourceName ?? DEFAULT_EVALUATED_SOURCE_NAME);
|
|
162
|
+
const evaluate = new Function("module", "exports", "require", `"use strict";\n${code}\n//# sourceURL=${sourceName}`);
|
|
163
|
+
evaluate(commonJsModule, commonJsModule.exports, trustedRequire);
|
|
164
|
+
return commonJsModule.exports;
|
|
165
|
+
}
|
|
166
|
+
function createHostExternalPlugin(allowedExternals) {
|
|
167
|
+
return {
|
|
168
|
+
name: "componentonce-host-externals",
|
|
169
|
+
setup(buildApi) {
|
|
170
|
+
buildApi.onResolve({ filter: /.*/ }, (args) => {
|
|
171
|
+
if (allowedExternals.has(args.path)) {
|
|
172
|
+
return { external: true, path: args.path };
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
errors: [
|
|
176
|
+
{
|
|
177
|
+
text: `Import "${args.path}" is not an allowed host external. ` +
|
|
178
|
+
"Add its exact specifier to externalModules (or additionalExternalModules for the React helper).",
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
};
|
|
182
|
+
});
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
function normalizeAllowedExternals(additionalExternals) {
|
|
187
|
+
const externals = new Set();
|
|
188
|
+
for (const specifier of additionalExternals) {
|
|
189
|
+
if (specifier.length === 0 ||
|
|
190
|
+
specifier !== specifier.trim() ||
|
|
191
|
+
specifier.includes("\0") ||
|
|
192
|
+
specifier.includes("\n") ||
|
|
193
|
+
specifier.includes("\r")) {
|
|
194
|
+
throw new ComponentOnceCompileError([
|
|
195
|
+
createInternalDiagnostic(`Invalid additional external module specifier: ${JSON.stringify(specifier)}.`),
|
|
196
|
+
]);
|
|
197
|
+
}
|
|
198
|
+
externals.add(specifier);
|
|
199
|
+
}
|
|
200
|
+
return externals;
|
|
201
|
+
}
|
|
202
|
+
function inferLoader(sourceFileName) {
|
|
203
|
+
const lowerName = sourceFileName.toLowerCase();
|
|
204
|
+
if (lowerName.endsWith(".jsx"))
|
|
205
|
+
return "jsx";
|
|
206
|
+
if (lowerName.endsWith(".js") || lowerName.endsWith(".mjs") || lowerName.endsWith(".cjs")) {
|
|
207
|
+
return "js";
|
|
208
|
+
}
|
|
209
|
+
if (lowerName.endsWith(".ts") || lowerName.endsWith(".mts") || lowerName.endsWith(".cts")) {
|
|
210
|
+
return "ts";
|
|
211
|
+
}
|
|
212
|
+
return "tsx";
|
|
213
|
+
}
|
|
214
|
+
function normalizeMessage(kind, message) {
|
|
215
|
+
return Object.freeze({
|
|
216
|
+
kind,
|
|
217
|
+
text: message.text,
|
|
218
|
+
...(message.location === null ? {} : { location: normalizeLocation(message.location) }),
|
|
219
|
+
notes: Object.freeze(message.notes.map((note) => Object.freeze({
|
|
220
|
+
text: note.text,
|
|
221
|
+
...(note.location === null ? {} : { location: normalizeLocation(note.location) }),
|
|
222
|
+
}))),
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
function normalizeLocation(location) {
|
|
226
|
+
return Object.freeze({
|
|
227
|
+
file: location.file,
|
|
228
|
+
line: location.line,
|
|
229
|
+
column: location.column,
|
|
230
|
+
length: location.length,
|
|
231
|
+
lineText: location.lineText,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
function createInternalDiagnostic(text) {
|
|
235
|
+
return Object.freeze({ kind: "error", text, notes: Object.freeze([]) });
|
|
236
|
+
}
|
|
237
|
+
function formatCompileErrorMessage(diagnostics) {
|
|
238
|
+
const details = diagnostics.map((diagnostic) => {
|
|
239
|
+
const location = diagnostic.location;
|
|
240
|
+
const prefix = location === undefined
|
|
241
|
+
? diagnostic.kind
|
|
242
|
+
: `${location.file}:${location.line}:${location.column + 1}`;
|
|
243
|
+
return `${prefix}: ${diagnostic.text}`;
|
|
244
|
+
});
|
|
245
|
+
return `ComponentOnce compilation failed${details.length === 0 ? "." : `:\n${details.join("\n")}`}`;
|
|
246
|
+
}
|
|
247
|
+
function isBuildFailure(error) {
|
|
248
|
+
return (typeof error === "object" &&
|
|
249
|
+
error !== null &&
|
|
250
|
+
"errors" in error &&
|
|
251
|
+
Array.isArray(error.errors));
|
|
252
|
+
}
|
|
253
|
+
function collectExternalModules(metafile) {
|
|
254
|
+
const modules = new Set();
|
|
255
|
+
for (const output of Object.values(metafile.outputs)) {
|
|
256
|
+
for (const imported of output.imports) {
|
|
257
|
+
if (imported.external)
|
|
258
|
+
modules.add(imported.path);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return [...modules].sort();
|
|
262
|
+
}
|
|
263
|
+
function hashBundleSource(source) {
|
|
264
|
+
const bytes = typeof source === "string" ? Buffer.from(source, "utf8") : source;
|
|
265
|
+
const digest = createHash("sha256").update(bytes).digest();
|
|
266
|
+
return {
|
|
267
|
+
byteLength: bytes.byteLength,
|
|
268
|
+
sha256: digest.toString("hex"),
|
|
269
|
+
integrity: `sha256-${digest.toString("base64")}`,
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
function isBundleArtifact(source) {
|
|
273
|
+
return typeof source === "object" && !(source instanceof Uint8Array);
|
|
274
|
+
}
|
|
275
|
+
function decodeUtf8(source) {
|
|
276
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(source);
|
|
277
|
+
}
|
|
278
|
+
function sanitizeSourceName(sourceName) {
|
|
279
|
+
return sourceName.replace(/[\r\n\u2028\u2029]/g, "_");
|
|
280
|
+
}
|
|
281
|
+
function deepFreeze(value) {
|
|
282
|
+
if (value !== null && typeof value === "object" && !Object.isFrozen(value)) {
|
|
283
|
+
for (const child of Object.values(value)) {
|
|
284
|
+
deepFreeze(child);
|
|
285
|
+
}
|
|
286
|
+
Object.freeze(value);
|
|
287
|
+
}
|
|
288
|
+
return value;
|
|
289
|
+
}
|
|
290
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,KAAK,GAMN,MAAM,SAAS,CAAC;AAEjB,0FAA0F;AAC1F,MAAM,CAAC,MAAM,mCAAmC,GAAG,8BAAuC,CAAC;AAE3F,MAAM,wBAAwB,GAAG,yBAAyB,CAAC;AAC3D,MAAM,8BAA8B,GAAG,0BAA0B,CAAC;AAClE,MAAM,6BAA6B,GAAG,iCAAiC,CAAC;AACxE,MAAM,eAAe,GAAG,CAAC,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,CAAU,CAAC;AAwFzF,uEAAuE;AACvE,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAClD,qDAAqD;IAC5C,WAAW,CAAqC;IAEzD,YAAY,WAA+C;QACzD,KAAK,CAAC,yBAAyB,CAAC,WAAW,CAAC,CAAC,CAAC;QAC9C,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;QACxC,IAAI,CAAC,WAA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
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@componentonce/compiler-esbuild",
|
|
3
|
+
"version": "0.1.0-beta.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist",
|
|
7
|
+
"README.md"
|
|
8
|
+
],
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"esbuild": "^0.27.0",
|
|
17
|
+
"@componentonce/core": "0.1.0-beta.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/node": "^24.10.0",
|
|
21
|
+
"@types/react": "^19.2.2",
|
|
22
|
+
"@types/react-dom": "^19.2.2",
|
|
23
|
+
"react": "^19.2.0",
|
|
24
|
+
"react-dom": "^19.2.0",
|
|
25
|
+
"typescript": "^5.9.3",
|
|
26
|
+
"vitest": "^4.0.5"
|
|
27
|
+
},
|
|
28
|
+
"description": "Optional esbuild compiler and trusted loader for dynamically loaded ComponentOnce modules.",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public",
|
|
32
|
+
"tag": "beta"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsc -p tsconfig.json",
|
|
36
|
+
"check": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p tsconfig.test.json",
|
|
37
|
+
"test": "vitest run"
|
|
38
|
+
}
|
|
39
|
+
}
|