From 56faee0b44df17d2080485646755df5062961679 Mon Sep 17 00:00:00 2001
From: Thuc Pham <51660321+thucpn@users.noreply.github.com>
Date: Thu, 21 Mar 2024 13:25:32 +0700
Subject: [PATCH] fix: fix windows e2e (#13)

---
 .changeset/chatty-toes-retire.md | 5 +++++
 .github/workflows/e2e.yml        | 4 ++--
 .gitignore                       | 3 +++
 CONTRIBUTING.md                  | 4 ++--
 index.ts                         | 1 -
 package.json                     | 6 +++---
 scripts/build.sh                 | 7 +++++++
 scripts/pack.sh                  | 3 +++
 8 files changed, 25 insertions(+), 8 deletions(-)
 create mode 100644 .changeset/chatty-toes-retire.md
 create mode 100644 scripts/build.sh
 create mode 100644 scripts/pack.sh

diff --git a/.changeset/chatty-toes-retire.md b/.changeset/chatty-toes-retire.md
new file mode 100644
index 00000000..239fbe69
--- /dev/null
+++ b/.changeset/chatty-toes-retire.md
@@ -0,0 +1,5 @@
+---
+"create-llama": patch
+---
+
+Add windows e2e tests
diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml
index 428944d9..4d74c8bd 100644
--- a/.github/workflows/e2e.yml
+++ b/.github/workflows/e2e.yml
@@ -17,7 +17,7 @@ jobs:
       matrix:
         node-version: [18, 20]
         python-version: ["3.11"]
-        os: [macos-latest] #, windows-latest]
+        os: [macos-latest, windows-latest]
     defaults:
       run:
         shell: bash
@@ -47,7 +47,7 @@ jobs:
         run: pnpm run build
         working-directory: .
       - name: Install
-        run: pnpm run install-local
+        run: pnpm run pack-install
         working-directory: .
       - name: Run Playwright tests
         run: pnpm run e2e
diff --git a/.gitignore b/.gitignore
index a2cade9e..6c50932b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -45,3 +45,6 @@ e2e/cache
 
 # intellij
 **/.idea
+
+# build artifacts
+create-llama-*.tgz
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 55f2c30b..2b82150d 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -32,10 +32,10 @@ To install it, call:
 pnpm exec playwright install --with-deps
 ```
 
-Then you can first install the `create-llama` command locally:
+Then you can create a global `create-llama` command (used by the e2e tests) that is linked to your local dev environment (if you update the build, you don't need to re-link):
 
 ```
-pnpm run install-local
+pnpm link --global
 ```
 
 And then finally run the tests:
diff --git a/index.ts b/index.ts
index f14c7927..15f453ed 100644
--- a/index.ts
+++ b/index.ts
@@ -1,4 +1,3 @@
-#!/usr/bin/env node
 /* eslint-disable import/no-extraneous-dependencies */
 import { execSync } from "child_process";
 import Commander from "commander";
diff --git a/package.json b/package.json
index bca0a4f9..a2daa6e5 100644
--- a/package.json
+++ b/package.json
@@ -24,15 +24,15 @@
     "format": "prettier --ignore-unknown --cache --check .",
     "format:write": "prettier --ignore-unknown --write .",
     "dev": "ncc build ./index.ts -w -o dist/",
-    "build": "npm run clean && ncc build ./index.ts -o ./dist/ --minify --no-cache --no-source-map-register",
+    "build": "bash ./scripts/build.sh",
     "lint": "eslint . --ignore-pattern dist --ignore-pattern e2e/cache",
     "e2e": "playwright test",
     "prepare": "husky",
-    "install-local": "pnpm link --global",
     "release": "pnpm run build && changeset publish",
     "new-version": "pnpm run build && changeset version",
     "release-snapshot": "pnpm run build && changeset publish --tag snapshot",
-    "new-snapshot": "pnpm run build && changeset version --snapshot"
+    "new-snapshot": "pnpm run build && changeset version --snapshot",
+    "pack-install": "bash ./scripts/pack.sh"
   },
   "devDependencies": {
     "@playwright/test": "^1.41.1",
diff --git a/scripts/build.sh b/scripts/build.sh
new file mode 100644
index 00000000..d11d4548
--- /dev/null
+++ b/scripts/build.sh
@@ -0,0 +1,7 @@
+#!/usr/bin/env bash
+
+# build dist/index.js file
+npm run clean && ncc build ./index.ts -o ./dist/ --minify --no-cache --no-source-map-register
+
+# add shebang to the top of dist/index.js (space after shebang is to fix windows issue)
+echo '#!/usr/bin/env node ' | cat - dist/index.js > temp && mv temp dist/index.js
\ No newline at end of file
diff --git a/scripts/pack.sh b/scripts/pack.sh
new file mode 100644
index 00000000..3009ef80
--- /dev/null
+++ b/scripts/pack.sh
@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+
+pnpm pack && npm install -g $(pwd)/$(ls ./*.tgz | head -1)
\ No newline at end of file
-- 
GitLab