-
Notifications
You must be signed in to change notification settings - Fork 24
Enhance LWC build process and add test cases for USING SCOPE #282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
3797a31
feat: add additional test-cases for USING SCOPE to ensure compatibility
paustint 618ef34
feat: enhance LWC build process with new artifacts and improved metad…
paustint 120dd2b
chore: update release workflow permissions and npm setup for improved…
paustint File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,104 @@ | ||
| import { build } from 'esbuild'; | ||
| import { readFileSync, writeFileSync, rmSync, mkdirSync, copyFileSync } from 'node:fs'; | ||
| import { execFileSync } from 'node:child_process'; | ||
|
|
||
| const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')); | ||
| const repoUrl = (pkg.repository?.url ?? '').replace(/^git\+/, '').replace(/\.git$/, ''); | ||
|
|
||
| const banner = `/*! | ||
| * ${pkg.name} v${pkg.version} | ||
| * ${repoUrl} | ||
| * @license ${pkg.license} | ||
| */`; | ||
|
|
||
| const LWC_COMPONENT_NAME = 'soqlParserJs'; | ||
| const LWC_STANDALONE_DIR = 'dist/lwc'; | ||
| const LWC_STANDALONE_FILE = `${LWC_STANDALONE_DIR}/${LWC_COMPONENT_NAME}.js`; | ||
| const LWC_PACKAGE_DIR = 'dist/lwc-packaged'; | ||
| const LWC_PACKAGE_BUNDLE_DIR = `${LWC_PACKAGE_DIR}/lwc/${LWC_COMPONENT_NAME}`; | ||
|
|
||
| const targets = { | ||
| esm: { | ||
| entryPoints: ['src/index.ts'], | ||
| outfile: 'dist/esm/index.mjs', | ||
| format: 'esm', | ||
| }, | ||
| lwc: { | ||
| entryPoints: ['src/index.ts'], | ||
| outfile: LWC_STANDALONE_FILE, | ||
| format: 'esm', | ||
| // LWC's compiler doesn't support certain ES2022 syntax | ||
| target: 'es2020', | ||
| }, | ||
| cjs: { | ||
| entryPoints: ['src/index.ts'], | ||
| outfile: 'dist/cjs/index.js', | ||
| format: 'cjs', | ||
| }, | ||
| cli: { | ||
| entryPoints: ['cli/index.ts'], | ||
| outfile: 'dist/cli/index.js', | ||
| format: 'cjs', | ||
| platform: 'node', | ||
| }, | ||
| }; | ||
|
|
||
| const requested = process.argv[2]; | ||
| const names = requested ? [requested] : Object.keys(targets); | ||
|
|
||
| for (const name of names) { | ||
| if (!targets[name]) { | ||
| console.error(`Unknown build target: ${name}. Valid targets: ${Object.keys(targets).join(', ')}`); | ||
| process.exit(1); | ||
| } | ||
| } | ||
|
|
||
| await Promise.all( | ||
| names.map(async name => { | ||
| await build({ | ||
| bundle: true, | ||
| target: 'es2022', | ||
| banner: { js: banner }, | ||
| minify: true, | ||
| ...targets[name], | ||
| }); | ||
| if (name === 'lwc') { | ||
| writeLwcPackage(); | ||
| } | ||
| }), | ||
| ); | ||
|
|
||
| function writeLwcPackage() { | ||
| const apiVersion = pkg.salesforceApiVersion; | ||
| if (!apiVersion) { | ||
| throw new Error('Missing "salesforceApiVersion" in package.json — required for LWC package metadata.'); | ||
| } | ||
| mkdirSync(LWC_PACKAGE_BUNDLE_DIR, { recursive: true }); | ||
| copyFileSync(LWC_STANDALONE_FILE, `${LWC_PACKAGE_BUNDLE_DIR}/${LWC_COMPONENT_NAME}.js`); | ||
|
|
||
| const packageXml = `<?xml version="1.0" encoding="UTF-8"?> | ||
| <Package xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
| <types> | ||
| <members>${LWC_COMPONENT_NAME}</members> | ||
| <name>LightningComponentBundle</name> | ||
| </types> | ||
| <version>${apiVersion}</version> | ||
| </Package> | ||
| `; | ||
| const metaXml = `<?xml version="1.0" encoding="UTF-8"?> | ||
| <LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
| <apiVersion>${apiVersion}</apiVersion> | ||
| <isExposed>false</isExposed> | ||
| </LightningComponentBundle> | ||
| `; | ||
| writeFileSync(`${LWC_PACKAGE_DIR}/package.xml`, packageXml); | ||
| writeFileSync(`${LWC_PACKAGE_BUNDLE_DIR}/${LWC_COMPONENT_NAME}.js-meta.xml`, metaXml); | ||
| writeLwcZip(); | ||
| } | ||
|
|
||
| function writeLwcZip() { | ||
| const zipName = `soql-parser-js-lwc-v${pkg.version}.zip`; | ||
| const zipPath = `dist/${zipName}`; | ||
| rmSync(zipPath, { force: true }); | ||
| execFileSync('zip', ['-r', `../${zipName}`, '.'], { cwd: LWC_PACKAGE_DIR, stdio: 'inherit' }); | ||
|
paustint marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.