Skip to content

Commit

Permalink
chore: configure lint related files (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
devjiwonchoi authored Oct 12, 2023
1 parent edf5464 commit bcf15a7
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 47 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
with:
fetch-depth: 0

- uses: pnpm/action-setup@v2.2.4
- uses: pnpm/action-setup@v2

- name: Use Node ${{ matrix.node-version }}
uses: actions/setup-node@v3
Expand All @@ -34,11 +34,14 @@ jobs:
- name: Install Dependencies
run: pnpm install --frozen-lockfile --prefer-offline

- name: Lint
run: |
pnpm typecheck
pnpm build
pnpm test
- name: Typecheck
run: pnpm typecheck

- name: Build
run: pnpm build

- name: Test
run: pnpm test

release:
runs-on: ubuntu-latest
Expand Down
3 changes: 1 addition & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

# modify to pnpm after migration
npx lint-staged
pnpm lint-staged
6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dist/
test/fixtures/
test/integration/
test/unit/

pnpm-lock.yaml
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ For example:
}
```

The asterisk `*` will be replaced with your entry files, such as:
The asterisk `*` will be replaced with your entry files, such as:

```
- my-lib/
Expand Down Expand Up @@ -254,15 +254,17 @@ This will match the export names `"foo"` and `"bar"` and will be treated as the
}
```

> Note: Wildcard Exports currently only supports the exports key `"./*"`, which will match all the available entries.
> Note: Wildcard Exports currently only supports the exports key `"./*"`, which will match all the available entries.
### CSS

`bunchee`` has basic CSS support for pure CSS file imports. It will be bundled into js bundle and insert the style tag into the document head when the bundle is loaded by browser.

```css
/* src/style.css */
.foo { color: orange; }
.foo {
color: orange;
}
```

```tsx
Expand Down
8 changes: 3 additions & 5 deletions src/build-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,7 @@ function buildInputConfig(

const sizePlugin = sizeCollector.plugin(cwd)
// common plugins for both dts and ts assets that need to be processed
const commonPlugins = [
sizePlugin,
]
const commonPlugins = [sizePlugin]

let baseResolvedTsOptions
if (dts && useTypescript) {
Expand Down Expand Up @@ -155,8 +153,8 @@ function buildInputConfig(
tsconfig: tsConfigPath,
compilerOptions: {
...tsCompilerOptions,
...baseResolvedTsOptions
}
...baseResolvedTsOptions,
},
}),
]
: [
Expand Down
9 changes: 2 additions & 7 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ import type { CliArgs, BundleConfig } from './types'

import path from 'path'
import arg from 'arg'
import {
exit,
formatDuration,
getPackageMeta,
hasPackageJson,
} from './utils'
import { exit, formatDuration, getPackageMeta, hasPackageJson } from './utils'
import { logger } from './logger'
import { version } from '../package.json'

Expand Down Expand Up @@ -129,7 +124,7 @@ async function run(args: CliArgs) {
cwd,
target,
runtime,
external: args.external === null ? null : (args.external?.split(',') || []),
external: args.external === null ? null : args.external?.split(',') || [],
watch: !!watch,
minify: !!minify,
sourcemap: sourcemap === false ? false : true,
Expand Down
6 changes: 4 additions & 2 deletions src/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ export function getExportPaths(
}

if (!isCjsPackage && pkg.main && hasCjsExtension(pkg.main)) {
exit('Cannot export main field with .cjs extension in ESM package, only .mjs and .js extensions are allowed')
exit(
'Cannot export main field with .cjs extension in ESM package, only .mjs and .js extensions are allowed',
)
}

// main export '.' from main/module/typings
Expand Down Expand Up @@ -264,7 +266,7 @@ export function constructDefaultExportCondition(
const types = getTypings(value as PackageMetadata)
exportCondition = {
[packageType === 'commonjs' ? 'require' : 'import']: value,
...(types && {types}),
...(types && { types }),
}
} else {
exportCondition = value
Expand Down
2 changes: 1 addition & 1 deletion src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ export const logger = {
},
info(...arg: any) {
console.log(' ✓', ...arg)
}
},
}
21 changes: 11 additions & 10 deletions src/plugins/inline-css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function __insertCSS(code) {
`,
create(code: string) {
return `__insertCSS(${JSON.stringify(code)});`
}
},
},
cssAssertionImport: {
global: '',
Expand All @@ -37,17 +37,18 @@ function __insertCSS(code) {
const sheet = new CSSStyleSheet()
sheet.replaceSync(${JSON.stringify(code)})
export default sheet`
}
}
},
},
} as const

export function inlineCss(options: { skip?: boolean, exclude?: FilterPattern }): Plugin {
export function inlineCss(options: {
skip?: boolean
exclude?: FilterPattern
}): Plugin {
const filter = createFilter(['**/*.css'], options.exclude ?? [])
const cssTypeSet = new Set<
| 'cssImport'
// wait for rollup 4 for better support of assertion support https://github.com/rollup/rollup/issues/4818
// | 'cssAssertionImport'
>()
const cssTypeSet = new Set<'cssImport'>()
// wait for rollup 4 for better support of assertion support https://github.com/rollup/rollup/issues/4818
// | 'cssAssertionImport'

return {
name: 'inline-css',
Expand All @@ -74,6 +75,6 @@ export function inlineCss(options: { skip?: boolean, exclude?: FilterPattern }):
code: `${prefix}${code}`,
map: { mappings: '' },
}
}
},
}
}
6 changes: 1 addition & 5 deletions src/plugins/size-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,4 @@ function logSizeStats() {
})
}

export {
logSizeStats,
sizeCollector,
createChunkSizeCollector
}
export { logSizeStats, sizeCollector, createChunkSizeCollector }
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,4 @@ export const hasAvailableExtension = (filename: string): boolean =>
availableExtensions.includes(path.extname(filename).slice(1))

export const hasCjsExtension = (filename: string): boolean =>
path.extname(filename) === '.cjs'
path.extname(filename) === '.cjs'
4 changes: 2 additions & 2 deletions test/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ const testCases: {
[content.includes('dot-js-dep'), true],
[content.includes('dot-cjs-dep'), true],
]
}
}
},
},
]

describe('cli', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/compile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ for (const unitName of unitTestDirs) {
const dir = resolve(baseUnitTestDir, unitName)
const inputFile = resolve(dir, 'input')
const ext = ['.js', '.jsx', '.ts', '.tsx'].find((ext) =>
fs.existsSync(`${inputFile}${ext}`)
fs.existsSync(`${inputFile}${ext}`),
)
if (!ext) {
throw new Error(`input.<ext> file found in ${dir}`)
Expand Down
4 changes: 2 additions & 2 deletions test/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ const testCases: {
expect(stderr).toContain(
'Cannot export main field with .cjs extension in ESM package, only .mjs and .js extensions are allowed',
)
}
}
},
},
]

async function runBundle(
Expand Down

0 comments on commit bcf15a7

Please sign in to comment.