-
-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(custom-esbuild): add support for plugin configuration
- Loading branch information
1 parent
ca8c2ed
commit 81f145d
Showing
17 changed files
with
217 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
examples/custom-esbuild/sanity-esbuild-app-esm/esbuild/define-text-by-option-plugin.cjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
function defineTitleByOptionPlugin(pluginOptions) { | ||
return { | ||
name: 'define-title', | ||
setup(build) { | ||
const options = build.initialOptions; | ||
options.define.titleByOption = JSON.stringify(pluginOptions.title); | ||
}, | ||
}; | ||
}; | ||
|
||
module.exports = defineTitleByOptionPlugin; |
11 changes: 11 additions & 0 deletions
11
examples/custom-esbuild/sanity-esbuild-app-esm/esbuild/define-text-by-option-plugin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
function defineTitleByOptionPlugin(pluginOptions) { | ||
return { | ||
name: 'define-title', | ||
setup(build) { | ||
const options = build.initialOptions; | ||
options.define.titleByOption = JSON.stringify(pluginOptions.title); | ||
}, | ||
}; | ||
}; | ||
|
||
export default defineTitleByOptionPlugin; |
13 changes: 13 additions & 0 deletions
13
examples/custom-esbuild/sanity-esbuild-app-esm/esbuild/define-text-by-option-plugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import type { Plugin, PluginBuild } from 'esbuild'; | ||
|
||
function defineTitleByOptionPlugin(pluginOptions: {title: string}): Plugin { | ||
return { | ||
name: 'define-title', | ||
setup(build: PluginBuild) { | ||
const options = build.initialOptions; | ||
options.define!['titleByOption'] = JSON.stringify(pluginOptions.title); | ||
}, | ||
}; | ||
}; | ||
|
||
export default defineTitleByOptionPlugin; |
1 change: 1 addition & 0 deletions
1
examples/custom-esbuild/sanity-esbuild-app-esm/src/app/app.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
<h1>{{ title }}</h1> | ||
<h2>{{ subtitle }}</h2> | ||
<h3>{{ titleByOption }}</h3> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
examples/custom-esbuild/sanity-esbuild-app/esbuild/define-text-by-option-plugin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
function defineTitleByOptionPlugin(pluginOptions) { | ||
return { | ||
name: 'define-title', | ||
setup(build) { | ||
const options = build.initialOptions; | ||
options.define.titleByOption = JSON.stringify(pluginOptions.title); | ||
}, | ||
}; | ||
}; | ||
|
||
module.exports = defineTitleByOptionPlugin; |
11 changes: 11 additions & 0 deletions
11
examples/custom-esbuild/sanity-esbuild-app/esbuild/define-text-by-option-plugin.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
function defineTitleByOptionPlugin(pluginOptions) { | ||
return { | ||
name: 'define-title', | ||
setup(build) { | ||
const options = build.initialOptions; | ||
options.define.titleByOption = JSON.stringify(pluginOptions.title); | ||
}, | ||
}; | ||
}; | ||
|
||
export default defineTitleByOptionPlugin; |
1 change: 1 addition & 0 deletions
1
examples/custom-esbuild/sanity-esbuild-app/src/app/app.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
<h1>{{ title }}</h1> | ||
<h2>{{ subtitle }}</h2> | ||
<h3>{{ titleByOption }}</h3> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { loadPlugins } from './load-plugins'; | ||
|
||
describe('loadPlugin', () => { | ||
beforeEach(() => { | ||
jest.resetModules(); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should load a plugin without configuration', async () => { | ||
const pluginFactory = jest.fn(); | ||
jest.mock('test/test-plugin.js', () => pluginFactory, { virtual: true }); | ||
const plugin = await loadPlugins(['test-plugin.js'], './test', './tsconfig.json', null as any); | ||
|
||
expect(pluginFactory).not.toHaveBeenCalled(); | ||
expect(plugin).toBeDefined(); | ||
}); | ||
|
||
it('should load a plugin with configuration', async () => { | ||
const pluginFactory = jest.fn(); | ||
jest.mock('test/test-plugin.js', () => pluginFactory, { virtual: true }); | ||
const plugin = await loadPlugins([{ path: 'test-plugin.js', options: { test: 'test' } }], './test', './tsconfig.json', null as any); | ||
|
||
expect(pluginFactory).toHaveBeenCalledWith({ test: 'test' }); | ||
expect(plugin).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters