Skip to content
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

fix: get the package build target working #73

Merged
merged 4 commits into from Nov 8, 2019

Conversation

EricCornelson
Copy link
Contributor

These changes get both the parcel bundling and vsix build targets working together.

A few important changes to note:

  • Separated the packaging phase to use the dist folder instead of out. This helps keep packaging completely separate from the normal debug/dev builds
  • As a result of the above change, the vsce package command now runs inside of the dist folder, so we need to copy any other needed files there as well (atm that's package.json, package.nls.json, and LICENSE)
  • Changed the gulpfile to use the command-line version of vsce instead of the js lib. I found the js version very hard to debug because gulp tends to swallow console.log statements, so the build would fail with zero diagnostic output. Using the command line api solves that problem and makes builds easier to debug.
  • Moved the tsconfig out of the src dir and into the root. I did this mainly because we are referencing the package.json in some parts of the code now, and if we use require(''), parcel can't resolve it, because we've gone one level deeper (from src to out/src). The solution to this is to use typescript import to import package.json. On compile, ts knows to change the relative path based on the output dir. But in order to let ts actually do this, we have to change the root of the ts project so that package.json is inside of it.

@connor4312
Copy link
Member

I ran into an issue running the package command--does it work for you?

image

@EricCornelson
Copy link
Contributor Author

It is working for me. Hmmm. Did the package script work for you before? I switched it from using the .ts files directly to using the compiled .js in out/ because it would ignore some typscript errors.

@connor4312
Copy link
Member

The package script didn't work before, but I pushed some changes that I had lying around from a while ago that fixed it for me. I'll look around at what it's doing some more tomorrow, it's odd that it works for only one of us, package-lock'd installations should be identical.

@EricCornelson
Copy link
Contributor Author

Indeed. Are you on Windows or Mac?

@connor4312
Copy link
Member

Mac

@EricCornelson
Copy link
Contributor Author

Ahh, I'll see if I get the same error in WSL

@connor4312
Copy link
Member

connor4312 commented Nov 6, 2019

I'm still not sure why it works for you--we used to have vscode as a direct dependency, but no longer do (since it's advised to depend on the separate types file), maybe that's still lying around on your disk? The docs say that vscode should be marked as external. They don't have built-in support for externals like Webpack does, but someone wrote a plugin that might work. We could do that, or swap over to Webpack for this build. I have a preference to Webpack just because I've lots of experience with it as a user and plugin author, but don't feel strongly.

This webpack config makes it work for me, though I later get an error The specified icon 'extension/resources/pwa.png' wasn't found in the extension.

diff --git a/gulpfile.js b/gulpfile.js
index 73788dc..8397dd5 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -13,6 +13,7 @@ const ts = require('gulp-typescript');
 const tslint = require('gulp-tslint');
 const typescript = require('typescript');
 const vsce = require('vsce');
+const webpack = require('webpack');
 const execSync = require('child_process').execSync;
 
 const dirname = 'vscode-node-debug3';
@@ -82,12 +83,42 @@ gulp.task(
 gulp.task('compile', gulp.parallel('compile:ts', 'compile:static'));
 
 /** Run parcel to bundle the extension output files */
-gulp.task('bundle', () => {
-  const parcelPath = path.join('node_modules', '.bin', 'parcel');
-  const extensionPath = path.join(buildSrcDir, 'extension.js');
-  const bootloaderPath = path.join(buildSrcDir, nodeTargetsDir, 'bootloader.js');
-  const watchdogPath = path.join(buildSrcDir, nodeTargetsDir, 'watchdog.js');
-  return runCommand(`${parcelPath} build ${extensionPath} ${bootloaderPath} ${watchdogPath} --target node -d ${distSrcDir} --no-source-maps --bundle-node-modules`, { stdio: 'inherit' })
+gulp.task('bundle', async () => {
+  const packages = [
+    { entry: path.join(buildSrcDir, 'extension.js'), library: true },
+    { entry: path.join(buildSrcDir, nodeTargetsDir, 'bootloader.js'), library: false },
+    { entry: path.join(buildSrcDir, nodeTargetsDir, 'watchdog.js'), library: false },
+  ];
+
+  for (const { entry, library } of packages) {
+    const config = {
+      mode: 'production',
+      target: 'node',
+      entry: path.resolve(entry),
+      output: {
+        path: path.resolve(distSrcDir),
+        filename: path.basename(entry),
+        devtoolModuleFilenameTemplate: '../[resource-path]',
+      },
+      externals: {
+        vscode: 'commonjs vscode',
+      },
+    };
+
+    if (library) {
+      config.output.libraryTarget = 'commonjs2';
+    }
+
+    await new Promise((resolve, reject) => webpack(config, (err, stats) => {
+      if (err) {
+        reject(err);
+      } else if (stats.hasErrors()) {
+        reject(stats);
+      } else {
+        resolve();
+      }
+    }));
+  }
 });
 
 // TODO: check the output location of watchdog/bootloader make sure it will work in out/src
@@ -216,4 +247,4 @@ function runCommand(cmd, options) {
     }
     resolve();
   });
-}
\ No newline at end of file
+}

@EricCornelson
Copy link
Contributor Author

I'm fine with switching to webpack if it's easier to get working everywhere. I'll try out that config.

These changes get both the parcel bundling and vsix build targets working together.

A few changes to note:
- Separated the packaging phase to use the dist folder instead of out. This helps keep packaging completely separate from the normal debug/dev builds
- As a result of the above change, the vsce package command now runs inside of the dist folder, so we need to copy any other needed files there as well (atm that's package.json, package.nls.json, and LICENSE)
- Changed the gulpfile to use the command-line version of vsce instead of the js lib. I found the js version very hard to debug because gulp tends to swallow console.log statements, so the build would fail with zero diagnostic output. Using the command line api solves that problem and makes builds easier to debug.
- Moved the tsconfig out of the src dir and into the root. I did this mainly because we are referencing the package.json in some parts of the code now, and if we use require(''), parcel can't resolve it, because we've gone one level deeper (from src to out/src). The solution to this is to use typescript import to import package.json. On compile, ts knows to change the relative path based on the output dir. But in order to let ts actually do this, we have to change the root of the ts project so that package.json is inside of it.
Parcel seems to have issues with the vscode dependency on Mac/Linux?
gulp seems to be able to handle backslashes on windows, but is not always consistent in behavior (e.g. in this case, on windows gulp would copy the resources directory fully recursively, whereas on mac/linux it would only copy the files, not preserving the directory structure)
@EricCornelson
Copy link
Contributor Author

Alright, let's give it another shot. I merged in your webpack config and switched from parcel.

Everything is working for me on both Windows and Ubuntu 18.04, hopefully that means it works on Mac too (I don't have a Mac to test on ☹️)

@EricCornelson
Copy link
Contributor Author

Also a note if you install the extension, it will only work when launching with the proposed api flag due to: #80

@connor4312
Copy link
Member

Cool, thanks! I made a couple tweaks to ensure the bootloader and terminateProcess.sh script can be found, seems to work well now.

@connor4312 connor4312 merged commit 2e52650 into microsoft:master Nov 8, 2019
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--enable-proposed-api=msjsdiag.pwa-debugger",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this shouldn't be necessary?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants