Skip to content

Commit

Permalink
fix: windows output alias path (#566)
Browse files Browse the repository at this point in the history
### Windows Support

#### Core

* Using `path.posix` to normalize paths
* Using posix styles to display the output paths

#### Build

* Add `cross-env` to run commands with envs

Fixes #565
  • Loading branch information
huozhi authored Jul 29, 2024
1 parent ba77525 commit 98f7b31
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 26 deletions.
46 changes: 44 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,56 @@ on:
pull_request:

jobs:
install_and_test_win:
runs-on: windows-latest
timeout-minutes: 5
strategy:
matrix:
node-version: [20]

name: Windows - Node ${{ matrix.node-version }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: pnpm/action-setup@v3

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install Dependencies
run: pnpm install --frozen-lockfile --prefer-offline

- name: Typecheck
run: pnpm typecheck

- name: Build
run: pnpm build

- name: Test
run: |
pnpm test
pnpm test:post
install_and_test:
runs-on: ubuntu-latest
runs-on: [ubuntu-latest]
timeout-minutes: 5
strategy:
matrix:
node-version: [16, 18, 20]

name: Node ${{ matrix.node-version }}
name: Linux - Node ${{ matrix.node-version }}
steps:
- uses: actions/checkout@v3
with:
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
"scripts": {
"test": "jest --env node",
"test:update": "TEST_UPDATE_SNAPSHOT=1 pnpm test",
"test:post": "POST_BUILD=1 pnpm jest test/compile.test.ts test/integration.test.ts",
"test:post": "cross-env POST_BUILD=1 pnpm jest test/compile.test.ts test/integration.test.ts",
"test:ci": "[ -z $CI ] || pnpm test",
"clean": "rm -rf ./dist",
"typecheck": "tsc --noEmit && tsc -p test/tsconfig.json --noEmit",
"prepublishOnly": "pnpm clean && pnpm build && chmod +x ./dist/bin/cli.js && pnpm test:ci",
"tsx": "SWC_NODE_IGNORE_DYNAMIC=1 node -r @swc-node/register",
"ts-bunchee": "pnpm tsx ./src/bin/index.ts",
"cli": "cross-env SWC_NODE_IGNORE_DYNAMIC=1 node -r @swc-node/register",
"ts-bunchee": "pnpm cli ./src/bin/index.ts",
"build-dir": "pnpm ts-bunchee --cwd",
"build": "SWC_NODE_IGNORE_DYNAMIC=1 node -r @swc-node/register ./src/bin/index.ts --runtime node",
"build": "pnpm cli ./src/bin/index.ts --runtime node",
"format": "prettier --write .",
"prepare": "husky"
},
Expand Down Expand Up @@ -90,6 +90,7 @@
"@types/jest": "29.0.0",
"@types/node": "^20.4.1",
"bunchee": "link:./",
"cross-env": "^7.0.3",
"husky": "^9.0.11",
"jest": "29.0.1",
"lint-staged": "^15.2.2",
Expand Down
41 changes: 30 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/plugins/alias-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { OutputOptions, Plugin } from 'rollup'
import { Entries } from '../types'
import path from 'path'
import { posix } from 'path'
import { relativify } from '../lib/format'
import { getSpecialExportTypeFromConditionNames } from '../entries'
import { specialExportConventions } from '../constants'
Expand Down Expand Up @@ -138,14 +138,14 @@ export function aliasEntries({
srcBundle &&
resolvedModuleBundle
) {
const absoluteBundlePath = path.resolve(cwd, srcBundle)
const absoluteImportBundlePath = path.resolve(
const absoluteBundlePath = posix.resolve(cwd, srcBundle)
const absoluteImportBundlePath = posix.resolve(
cwd,
resolvedModuleBundle,
)

const filePathBase = path.relative(
path.dirname(absoluteBundlePath),
const filePathBase = posix.relative(
posix.dirname(absoluteBundlePath),
absoluteImportBundlePath,
)!
const relativePath = relativify(filePathBase)
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/output-state-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Plugin } from 'rollup'
import { type Entries } from '../types'
import path from 'path'
import path, { posix } from 'path'
import prettyBytes from 'pretty-bytes'
import pc from 'picocolors'
import { logger } from '../logger'
Expand Down Expand Up @@ -59,9 +59,9 @@ function createOutputState({ entries }: { entries: Entries }): {
return {
name: 'collect-sizes',
writeBundle(options, bundle) {
const dir = options.dir || path.dirname(options.file!)
const dir = options.dir || posix.dirname(options.file!)
Object.entries(bundle).forEach(([fileName, chunk]) => {
const filePath = path.join(dir, fileName)
const filePath = posix.join(dir, fileName)
if (chunk.type !== 'chunk') {
return
}
Expand All @@ -75,7 +75,7 @@ function createOutputState({ entries }: { entries: Entries }): {
)
addSize({
fileName: path.isAbsolute(cwd)
? path.relative(cwd, filePath)
? posix.relative(cwd, filePath)
: filePath,
size,
sourceFileName,
Expand Down

0 comments on commit 98f7b31

Please sign in to comment.