Skip to content

Commit

Permalink
remove browserify, replace with esbuild
Browse files Browse the repository at this point in the history
  • Loading branch information
kreddlear committed Jan 10, 2025
1 parent f935e72 commit cf9b258
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 766 deletions.
2 changes: 1 addition & 1 deletion packages/cli/docs/cli.html
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ <h2 id="build">build</h2>
<li>Copies all code into the temporary folder</li>
<li>Adds an entry point: <code>zapierwrapper.js</code></li>
<li>Generates and validates app definition.</li>
<li>Detects dependencies via browserify (optional, on by default)</li>
<li>Detects dependencies via esbuild (optional, on by default)</li>
<li>Zips up all needed <code>.js</code> files. If you want to include more files, add a &quot;includeInBuild&quot; property (array with strings of regexp paths) to your <code>.zapierapprc</code>.</li>
<li>Moves the zip to <code>build/build.zip</code> and <code>build/source.zip</code> and deletes the temp folder</li>
</ul><p>This command is typically followed by <code>zapier upload</code>.</p><p><strong>Flags</strong></p><ul>
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ This command does the following:
* Copies all code into the temporary folder
* Adds an entry point: `zapierwrapper.js`
* Generates and validates app definition.
* Detects dependencies via browserify (optional, on by default)
* Detects dependencies via esbuild (optional, on by default)
* Zips up all needed `.js` files. If you want to include more files, add a "includeInBuild" property (array with strings of regexp paths) to your `.zapierapprc`.
* Moves the zip to `build/build.zip` and `build/source.zip` and deletes the temp folder

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@
"@oclif/plugin-version": "2.2.16",
"adm-zip": "0.5.16",
"archiver": "7.0.1",
"browserify": "17.0.1",
"chrono-node": "2.7.7",
"cli-table3": "0.6.5",
"colors": "1.4.0",
"debug": "4.3.7",
"dotenv": "16.4.6",
"esbuild": "0.24.2",
"fs-extra": "11.2.0",
"gulp-filter": "7.0.0",
"gulp-prettier": "4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/oclif/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ This command does the following:
* Copies all code into the temporary folder
* Adds an entry point: \`zapierwrapper.js\`
* Generates and validates app definition.
* Detects dependencies via browserify (optional, on by default)
* Detects dependencies via esbuild (optional, on by default)
* Zips up all needed \`.js\` files. If you want to include more files, add a "includeInBuild" property (array with strings of regexp paths) to your \`${CURRENT_APP_FILE}\`.
* Moves the zip to \`${BUILD_PATH}\` and \`${SOURCE_PATH}\` and deletes the temp folder
Expand Down
6 changes: 4 additions & 2 deletions packages/cli/src/tests/utils/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ describe('build (runs slowly)', function () {
it('should list only required files', async function () {
this.retries(3); // retry up to 3 times

const smartPaths = await build.requiredFiles(tmpDir, [entryPoint]);

const smartPaths = await build.requiredFiles({
cwd: tmpDir,
entryPoints: [entryPoint],
});
// check that only the required lodash files are grabbed
smartPaths.should.containEql('index.js');
smartPaths.should.containEql('dist/index.js');
Expand Down
64 changes: 15 additions & 49 deletions packages/cli/src/utils/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ const crypto = require('crypto');
const os = require('os');
const path = require('path');

const browserify = require('browserify');
const through = require('through2');
const _ = require('lodash');
const archiver = require('archiver');
const esbuild = require('esbuild');
const fs = require('fs');
const fse = require('fs-extra');
const klaw = require('klaw');
Expand Down Expand Up @@ -52,57 +51,24 @@ const debug = require('debug')('zapier:build');
const stripPath = (cwd, filePath) => filePath.split(cwd).pop();

// given entry points in a directory, return a list of files that uses
// could probably be done better with module-deps...
// TODO: needs to include package.json files too i think
// https://github.com/serverless/serverless-optimizer-plugin?
const requiredFiles = (cwd, entryPoints) => {
const requiredFiles = async ({ cwd, entryPoints }) => {
if (!_.endsWith(cwd, path.sep)) {
cwd += path.sep;
}

const argv = {
noParse: [undefined],
extensions: [],
ignoreTransform: [],
entries: entryPoints,
fullPaths: false,
builtins: false,
commondir: false,
bundleExternal: true,
basedir: cwd,
browserField: false,
detectGlobals: true,
insertGlobals: false,
insertGlobalVars: {
process: undefined,
global: undefined,
'Buffer.isBuffer': undefined,
Buffer: undefined,
},
ignoreMissing: true,
debug: false,
standalone: undefined,
};
const b = browserify(argv);

return new Promise((resolve, reject) => {
b.on('error', reject);

const paths = [];
b.pipeline.get('deps').push(
through
.obj((row, enc, next) => {
const filePath = row.file || row.id;
paths.push(stripPath(cwd, filePath));
next();
})
.on('end', () => {
paths.sort();
resolve(paths);
}),
);
b.bundle();
const result = await esbuild.build({
entryPoints,
bundle: true,
platform: 'node',
// outfile: './build/bundle.js',
outdir: './build',
metafile: true,
logLevel: 'warning',
});

return Object.keys(result.metafile.inputs).map((path) =>
stripPath(cwd, path),
);
};

const listFiles = (dir) => {
Expand Down Expand Up @@ -203,7 +169,7 @@ const makeZip = async (dir, zipPath, disableDependencyDetection) => {

const [dumbPaths, smartPaths, appConfig] = await Promise.all([
listFiles(dir),
requiredFiles(dir, entryPoints),
requiredFiles({ cwd: dir, entryPoints: entryPoints }),
getLinkedAppConfig(dir).catch(() => ({})),
]);

Expand Down
Loading

0 comments on commit cf9b258

Please sign in to comment.