From 1a5fdea505700be78cf15c2fba159d14ce460f66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Nison?= Date: Thu, 20 Aug 2020 11:38:59 +0200 Subject: [PATCH 1/5] Uses the right package manager per the environment --- bin/asinit | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/bin/asinit b/bin/asinit index 557fc9c492..1b79b033ce 100755 --- a/bin/asinit +++ b/bin/asinit @@ -8,6 +8,30 @@ const colors = require("../cli/util/colors"); const version = require("../package.json").version; const options = require("../cli/util/options"); +const commands = { + "npm": { + install: "npm install", + run: "npm run", + test: "npm test" + }, + "yarn": { + install: "yarn install", + run: "yarn", + test: "yarn test" + }, + "pnpm": { + install: "pnpm install", + run: "pnpm run", + test: "pnpm test" + } +}; + +let pm = "npm"; +if (process.env.npm_config_user_agent.match(/\byarn\//)) + pm = "yarn"; +else if (process.env.npm_config_user_agent.match(/\bpnpm\//)) + pm = "pnpm"; + const asinitOptions = { "help": { "category": "General", @@ -118,14 +142,14 @@ function createProject(answer) { "", "Don't forget to install dependencies before you start:", "", - colors.white(" npm install"), + colors.white(" " + commands[pm].install), "", "To edit the entry file, open '" + colors.cyan("assembly/index.ts") + "' in your editor of choice.", "Create as many additional files as necessary and use them as imports.", "", "To build the entry file to WebAssembly when you are ready, run:", "", - colors.white(" npm run asbuild"), + colors.white(" " + commands[pm].run + " asbuild"), "", "Running the command above creates the following binaries incl. their respective", "text format representations and source maps:", @@ -146,7 +170,7 @@ function createProject(answer) { "", "To run the tests, do:", "", - colors.white(" npm test"), + colors.white(" " + commands[pm].test), "", "The AssemblyScript documentation covers all the details:", "", @@ -289,7 +313,7 @@ function ensurePackageJson() { const entryPath = path.relative(projectDir, entryFile).replace(/\\/g, "/"); const buildUntouched = "asc " + entryPath + " --target debug"; const buildOptimized = "asc " + entryPath + " --target release"; - const buildAll = "npm run asbuild:untouched && npm run asbuild:optimized"; + const buildAll = commands[pm].run + " asbuild:untouched && " + commands[pm].run + " asbuild:optimized"; if (!fs.existsSync(packageFile)) { fs.writeFileSync(packageFile, JSON.stringify({ "scripts": { From 368db3dec3c1c873b5e60df0276a393f1f73f87f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Nison?= Date: Thu, 20 Aug 2020 11:52:54 +0200 Subject: [PATCH 2/5] Update NOTICE --- NOTICE | 1 + 1 file changed, 1 insertion(+) diff --git a/NOTICE b/NOTICE index bf9e9abd64..198b982544 100644 --- a/NOTICE +++ b/NOTICE @@ -25,6 +25,7 @@ under the licensing terms detailed in LICENSE: * Guido Zuidhof * ncave <777696+ncave@users.noreply.github.com> * Andrew Davis +* Maƫl Nison Portions of this software are derived from third-party works licensed under the following terms: From cea49541f6e52d2b3d540b02c7265cb739965812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Nison?= Date: Thu, 20 Aug 2020 12:01:20 +0200 Subject: [PATCH 3/5] Apply suggestions from code review Co-authored-by: Max Graey --- bin/asinit | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/asinit b/bin/asinit index 1b79b033ce..97ef231200 100755 --- a/bin/asinit +++ b/bin/asinit @@ -27,9 +27,9 @@ const commands = { }; let pm = "npm"; -if (process.env.npm_config_user_agent.match(/\byarn\//)) +if (process.env.npm_config_user_agent.test(/\byarn\//)) pm = "yarn"; -else if (process.env.npm_config_user_agent.match(/\bpnpm\//)) +else if (process.env.npm_config_user_agent.test(/\bpnpm\//)) pm = "pnpm"; const asinitOptions = { From 8bf1bf76309ac0fdd6ba77d76711218248ad2299 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Nison?= Date: Thu, 20 Aug 2020 13:20:04 +0200 Subject: [PATCH 4/5] Update bin/asinit Co-authored-by: Daniel Wirtz --- bin/asinit | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/bin/asinit b/bin/asinit index 97ef231200..f58df2c234 100755 --- a/bin/asinit +++ b/bin/asinit @@ -27,10 +27,13 @@ const commands = { }; let pm = "npm"; -if (process.env.npm_config_user_agent.test(/\byarn\//)) - pm = "yarn"; -else if (process.env.npm_config_user_agent.test(/\bpnpm\//)) - pm = "pnpm"; +if (typeof process.env.npm_config_user_agent === "string") { + if (process.env.npm_config_user_agent.test(/\byarn\//)) { + pm = "yarn"; + } else if (process.env.npm_config_user_agent.test(/\bpnpm\//)) { + pm = "pnpm"; + } +} const asinitOptions = { "help": { From 093d6ac0aeac24602cac933b880df3461b2f7427 Mon Sep 17 00:00:00 2001 From: Daniel Wirtz Date: Thu, 20 Aug 2020 13:55:55 +0200 Subject: [PATCH 5/5] Update bin/asinit --- bin/asinit | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/asinit b/bin/asinit index f58df2c234..727534ba8e 100755 --- a/bin/asinit +++ b/bin/asinit @@ -28,9 +28,9 @@ const commands = { let pm = "npm"; if (typeof process.env.npm_config_user_agent === "string") { - if (process.env.npm_config_user_agent.test(/\byarn\//)) { + if (/\byarn\//.test(process.env.npm_config_user_agent)) { pm = "yarn"; - } else if (process.env.npm_config_user_agent.test(/\bpnpm\//)) { + } else if (/\bpnpm\//.test(process.env.npm_config_user_agent)) { pm = "pnpm"; } }