-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1030 from forcedotcom/mz/esbuild-workflow
chore: esbuild artifacts
- Loading branch information
Showing
4 changed files
with
177 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: esbuild Compilation & npm Publish Workflow | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
branch: | ||
description: 'Set the branch to use for automation tests' | ||
type: string | ||
required: false | ||
default: 'main' | ||
nodeVersion: | ||
description: version of node to use. It's better to specify latest, lts/* or lts/-1 than to hardode numbers | ||
type: string | ||
default: lts/* | ||
required: false | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ inputs.branch }} | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ inputs.nodeVersion }} | ||
registry-url: 'https://registry.npmjs.org' | ||
cache: yarn | ||
- name: Install esbuild Dependencies | ||
run: | | ||
yarn add -D esbuild@^0.19.5 esbuild-plugin-pino@^2.1.0 npm-dts@^1.3.12 esbuild-plugin-tsc@^0.4.0 | ||
- uses: salesforcecli/github-workflows/.github/actions/yarnInstallWithRetries@main | ||
- name: Update for Bundling | ||
run: | | ||
node scripts/updateForBundling.js | ||
- name: Generate Bundle | ||
run: | | ||
node scripts/build.js | ||
- name: Publish a Package | ||
run: | | ||
npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN | ||
npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
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,55 @@ | ||
/* | ||
* Copyright (c) 2023, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
const { build } = require('esbuild'); | ||
const esbuildPluginPino = require('esbuild-plugin-pino'); | ||
const esbuildPluginTsc = require('esbuild-plugin-tsc'); | ||
const { Generator } = require('npm-dts'); | ||
const fs = require('fs'); | ||
|
||
new Generator({ | ||
output: 'lib/exported.d.ts', | ||
}).generate(); | ||
|
||
const sharedConfig = { | ||
entryPoints: ['src/exported.ts'], | ||
bundle: true, | ||
// minify: true, | ||
plugins: [ | ||
esbuildPluginPino({ transports: ['pino-pretty'] }), | ||
esbuildPluginTsc({ | ||
tsconfigPath: './tsconfig.json', | ||
}), | ||
], | ||
}; | ||
|
||
(async () => { | ||
const result = await build({ | ||
...sharedConfig, | ||
// external: ['src/logger/transformStream.ts'], | ||
platform: 'node', // for CJS | ||
outdir: 'lib', | ||
}); | ||
const filePath = 'lib/exported.js'; | ||
let bundledEntryPoint = fs.readFileSync(filePath, 'utf8'); | ||
|
||
const searchString = /\$\{process\.cwd\(\)\}\$\{require\("path"\)\.sep\}lib/g; | ||
const replacementString = `\${__dirname}\${require("path").sep}`; | ||
|
||
bundledEntryPoint = bundledEntryPoint.replace(searchString, replacementString); | ||
fs.writeFileSync(filePath, bundledEntryPoint, 'utf8'); | ||
|
||
await build({ | ||
entryPoints: ['src/logger/transformStream.ts'], | ||
bundle: true, | ||
minify: true, | ||
outdir: 'lib', | ||
platform: 'node', // for CJS | ||
plugins: [ | ||
// esbuildPluginPino({ transports: ['pino-pretty'] }), | ||
], | ||
}); | ||
})(); |
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 @@ | ||
{ | ||
"extends": "@salesforce/dev-config/tsconfig-strict", | ||
"compilerOptions": { | ||
"outDir": "../lib", | ||
"resolveJsonModule": true, | ||
"esModuleInterop": true, | ||
"rootDir": "../src", | ||
"plugins": [{ "transform": "../src/messageTransformer.ts" }] | ||
}, | ||
"include": ["../src/**/*.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,67 @@ | ||
const fs = require('fs'); | ||
|
||
// Function to update package.json | ||
function updatePackageJson() { | ||
const packagePath = './package.json'; | ||
|
||
fs.readFile(packagePath, 'utf8', (err, data) => { | ||
if (err) { | ||
console.error(`Error reading package.json: ${err}`); | ||
return; | ||
} | ||
|
||
try { | ||
const packageJson = JSON.parse(data); | ||
|
||
// Update package name if necessary | ||
if (packageJson.name && packageJson.name === '@salesforce/core') { | ||
packageJson.name = '@salesforce/core-bundle'; | ||
} | ||
|
||
// Remove 'prepack' and 'prepare' scripts | ||
if (packageJson.scripts) { | ||
delete packageJson.scripts.prepack; | ||
delete packageJson.scripts.prepare; | ||
} | ||
|
||
fs.writeFile(packagePath, JSON.stringify(packageJson, null, 2), 'utf8', (writeErr) => { | ||
if (writeErr) { | ||
console.error(`Error writing to package.json: ${writeErr}`); | ||
} else { | ||
console.log('package.json updated successfully.'); | ||
} | ||
}); | ||
} catch (parseErr) { | ||
console.error(`Error parsing JSON in package.json: ${parseErr}`); | ||
} | ||
}); | ||
} | ||
|
||
// Function to update logger.ts | ||
function updateLoggerTs() { | ||
const loggerPath = './src/logger/logger.ts'; | ||
|
||
fs.readFile(loggerPath, 'utf8', (err, data) => { | ||
if (err) { | ||
console.error(`Error reading logger.ts: ${err}`); | ||
return; | ||
} | ||
|
||
let updatedData = data.replace( | ||
"target: path.join('..', '..', 'lib', 'logger', 'transformStream')", | ||
"target: './transformStream'" | ||
); | ||
|
||
fs.writeFile(loggerPath, updatedData, 'utf8', (writeErr) => { | ||
if (writeErr) { | ||
console.error(`Error writing to logger.ts: ${writeErr}`); | ||
} else { | ||
console.log('Logger.ts updated successfully.'); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
// Run the update functions | ||
updatePackageJson(); | ||
updateLoggerTs(); |