Skip to content

Commit 8330899

Browse files
committed
adding shims in the correct place
1 parent bb59022 commit 8330899

3 files changed

Lines changed: 34 additions & 6 deletions

File tree

packages/ink/src/document/Builder.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ export default class Builder {
5555
protected _extname = '.ink';
5656
//whether to minify the code
5757
protected _minify: boolean;
58-
//transpiler
58+
//shims need to be passed down to esbuild...
59+
protected _shims: [ string|RegExp, string ][];
60+
//transpiler
61+
// TODO: document transpiler is not being used here
62+
// so we need to figure out whether if it's okay to
63+
// remove this or not (it can be externally used...)
5964
protected _transpiler: Transpiler;
6065
//the file loader
6166
//the location of the tsconfig file
@@ -109,8 +114,9 @@ export default class Builder {
109114
} = options;
110115

111116
this._emitter = emitter;
112-
this._minify = minify;
113117
this._extname = extname;
118+
this._minify = minify;
119+
this._shims = shims;
114120

115121
//generated values
116122
this._tsconfig = tsconfig;
@@ -170,7 +176,8 @@ export default class Builder {
170176
cwd: this._document.cwd,
171177
fs: this._document.fs,
172178
tsconfig: this._tsconfig,
173-
extname: this._extname
179+
extname: this._extname,
180+
shims: this._shims
174181
})
175182
]
176183
}
@@ -259,7 +266,8 @@ export default class Builder {
259266
cwd: this._document.cwd,
260267
fs: this._document.fs,
261268
tsconfig: this._tsconfig,
262-
extname: this._extname
269+
extname: this._extname,
270+
shims: this._shims
263271
})
264272
]
265273
}

packages/ink/src/plugins.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export function esDocumentPlugin(options: DocumentPluginOptions = {}) {
112112
extname = '.ink',
113113
cwd = process.cwd(),
114114
fs = new NodeFS(),
115+
shims = [],
115116
...config
116117
} = options;
117118
const name = {
@@ -139,6 +140,10 @@ export function esDocumentPlugin(options: DocumentPluginOptions = {}) {
139140
{ ...config, fs, cwd, type: 'document' }
140141
);
141142
const transpiler = new DocumentTranspiler(document, tsconfig);
143+
//add shims to transpiler
144+
for (const [ key, value ] of shims) {
145+
transpiler.shim(key, value);
146+
}
142147
return {
143148
contents: toTS(transpiler.transpile()),
144149
loader: 'ts'
@@ -164,6 +169,10 @@ export function esDocumentPlugin(options: DocumentPluginOptions = {}) {
164169
{ ...config, fs, cwd, type: 'document' }
165170
);
166171
const transpiler = new DocumentTranspiler(document, tsconfig);
172+
//add shims to transpiler
173+
for (const [ key, value ] of shims) {
174+
transpiler.shim(key, value);
175+
}
167176
return {
168177
contents: toTS(transpiler.client()),
169178
loader: 'ts'
@@ -204,6 +213,7 @@ export function esInkPlugin(options: InkPluginOptions = {}) {
204213
fs = new NodeFS(),
205214
mode = 'server',
206215
extname = '.ink',
216+
shims = [],
207217
...config
208218
} = options;
209219
const loader = new FileLoader(fs, cwd);
@@ -252,6 +262,10 @@ export function esInkPlugin(options: InkPluginOptions = {}) {
252262
type: 'document'
253263
});
254264
const transpiler = new DocumentTranspiler(document, tsconfig);
265+
//add shims to transpiler
266+
for (const [ key, value ] of shims) {
267+
transpiler.shim(key, value);
268+
}
255269
return {
256270
contents: toTS(transpiler.transpile()),
257271
resolveDir: path.dirname(args.path),
@@ -270,6 +284,10 @@ export function esInkPlugin(options: InkPluginOptions = {}) {
270284
type: 'document'
271285
});
272286
const transpiler = new DocumentTranspiler(document, tsconfig);
287+
//add shims to transpiler
288+
for (const [ key, value ] of shims) {
289+
transpiler.shim(key, value);
290+
}
273291
return {
274292
contents: toTS(transpiler.client()),
275293
resolveDir: path.dirname(args.path),

packages/ink/src/types.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,8 @@ export type AliasPluginOptions = FileOptions;
526526
export type ComponentPluginOptions = FileOptions & {
527527
brand?: string,
528528
tsconfig?: string,
529-
extname?: string
529+
extname?: string,
530+
shims?: [ string|RegExp, string ][]
530531
};
531532
//options for esbuild plugin
532533
export type DocumentPluginOptions = ComponentPluginOptions;
@@ -537,7 +538,8 @@ export type InkPluginOptions = FileOptions & {
537538
brand?: string,
538539
mode?: 'client'|'server',
539540
tsconfig?: string,
540-
extname?: string
541+
extname?: string,
542+
shims?: [ string|RegExp, string ][]
541543
};
542544

543545
//options for the component class

0 commit comments

Comments
 (0)