-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e32558
commit a8484c8
Showing
4 changed files
with
181 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,48 @@ | ||
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' | ||
- name: Install esbuild Dependencies | ||
run: | | ||
yarn add esbuild@^0.19.5 -D | ||
yarn add esbuild-plugin-pino@^2.1.0 -D | ||
yarn add npm-dts@^1.3.12 -D | ||
yarn add esbuild-plugin-tsc@^0.4.0 -D | ||
- name: Install All Dependencies | ||
run: | | ||
yarn install --network-timeout 600000 | ||
- 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(); |
a8484c8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logger Benchmarks - ubuntu-latest
Child logger creation
469236
ops/sec (±1.34%
)475160
ops/sec (±1.21%
)1.01
Logging a string on root logger
772749
ops/sec (±8.53%
)692013
ops/sec (±7.60%
)0.90
Logging an object on root logger
593952
ops/sec (±6.73%
)503291
ops/sec (±8.01%
)0.85
Logging an object with a message on root logger
9418
ops/sec (±201.83%
)18923
ops/sec (±186.56%
)2.01
Logging an object with a redacted prop on root logger
388988
ops/sec (±13.63%
)396658
ops/sec (±10.38%
)1.02
Logging a nested 3-level object on root logger
353950
ops/sec (±8.47%
)406521
ops/sec (±4.43%
)1.15
This comment was automatically generated by workflow using github-action-benchmark.
a8484c8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible performance regression was detected for benchmark 'Logger Benchmarks - ubuntu-latest'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
2
.Logging an object with a message on root logger
9418
ops/sec (±201.83%
)18923
ops/sec (±186.56%
)2.01
This comment was automatically generated by workflow using github-action-benchmark.
a8484c8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible performance regression was detected for benchmark 'Logger Benchmarks - windows-latest'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
2
.Logging an object with a redacted prop on root logger
4133
ops/sec (±220.21%
)470352
ops/sec (±8.12%
)113.80
This comment was automatically generated by workflow using github-action-benchmark.
a8484c8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logger Benchmarks - windows-latest
Child logger creation
307386
ops/sec (±0.90%
)344091
ops/sec (±0.53%
)1.12
Logging a string on root logger
627390
ops/sec (±9.49%
)832656
ops/sec (±11.80%
)1.33
Logging an object on root logger
516640
ops/sec (±7.64%
)580185
ops/sec (±5.56%
)1.12
Logging an object with a message on root logger
313807
ops/sec (±5.82%
)8653
ops/sec (±199.97%
)0.02757427335910289
Logging an object with a redacted prop on root logger
4133
ops/sec (±220.21%
)470352
ops/sec (±8.12%
)113.80
Logging a nested 3-level object on root logger
222262
ops/sec (±23.28%
)338876
ops/sec (±5.16%
)1.52
This comment was automatically generated by workflow using github-action-benchmark.