Skip to content

Commit

Permalink
feat!: migrate to esm
Browse files Browse the repository at this point in the history
  • Loading branch information
YunYouJun committed Oct 2, 2023
1 parent bc60967 commit 74ed01c
Show file tree
Hide file tree
Showing 14 changed files with 128 additions and 84 deletions.
15 changes: 11 additions & 4 deletions .github/workflows/ci.yml
Expand Up @@ -17,7 +17,7 @@ jobs:
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v3
with:
node-version: 16.x
node-version: 18.x
cache: pnpm

- name: Install
Expand All @@ -33,7 +33,7 @@ jobs:
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v3
with:
node-version: 16.x
node-version: 18.x
cache: pnpm

- name: Install
Expand All @@ -49,7 +49,7 @@ jobs:

strategy:
matrix:
node-version: [16.x]
node-version: [18.x]
os: [ubuntu-latest, windows-latest]
fail-fast: false

Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:

strategy:
matrix:
node-version: [16.x]
node-version: [18.x]
os: [ubuntu-latest]
fail-fast: false

Expand All @@ -99,6 +99,13 @@ jobs:

test-e2e:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x]
os: [ubuntu-latest]
fail-fast: false

steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
Expand Down
3 changes: 2 additions & 1 deletion demo/yun/package.json
Expand Up @@ -3,11 +3,12 @@
"valaxy": {
"theme": "yun"
},
"type": "module",
"scripts": {
"build": "npm run fuse && npm run build:ssg && npm run rss",
"build:spa": "valaxy build",
"build:ssg": "valaxy build --ssg --log=info",
"dev": "nodemon -w \"../../packages/valaxy/dist/*.cjs\" --exec \"valaxy . --port 3333\"",
"dev": "nodemon -w \"../../packages/valaxy/dist/*.mjs\" --exec \"valaxy . --port 3333\"",
"fuse": "valaxy fuse",
"new": "valaxy new",
"rss": "valaxy rss",
Expand Down
4 changes: 4 additions & 0 deletions demo/yun/pages/posts/hello-valaxy.md
Expand Up @@ -12,6 +12,10 @@ outline: deep
excerpt: Valaxy aims to be a next generation of static blogging frameworks/generators.
---

```md
{{ frontmatter }}
```

{{ frontmatter }}

## What is Valaxy? {lang="en"}
Expand Down
2 changes: 1 addition & 1 deletion packages/create-valaxy-theme/package.json
Expand Up @@ -22,7 +22,7 @@
"node": "^14.18.0 || >=16.0.0"
},
"dependencies": {
"execa": "5.1.1",
"execa": "8.0.1",
"kolorist": "^1.8.0",
"minimist": "^1.2.8",
"prompts": "^2.4.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/create-valaxy/package.json
Expand Up @@ -21,7 +21,7 @@
"node": "^14.18.0 || >=16.0.0"
},
"dependencies": {
"execa": "5.1.1",
"execa": "8.0.1",
"kolorist": "^1.8.0",
"minimist": "^1.2.8",
"prompts": "^2.4.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/valaxy/node/cli/utils/fs.ts
@@ -1,5 +1,5 @@
import { type PathLike } from 'node:fs'
import { access } from 'fs-extra'
import { access } from 'node:fs/promises'

export async function exists(path: PathLike) {
try {
Expand Down
4 changes: 2 additions & 2 deletions packages/valaxy/node/cli/utils/post.ts
@@ -1,5 +1,5 @@
import { join, resolve } from 'node:path'
import { writeFile } from 'fs-extra'
import { writeFile } from 'node:fs/promises'
import { render } from 'ejs'
import dayjs from 'dayjs'
import { ensureSuffix } from '@antfu/utils'
Expand Down Expand Up @@ -37,7 +37,7 @@ export async function create(data: CreatePostParams) {
if (!await exists(destinationPath)) {
const content = await genLayoutTemplate(data)
try {
writeFile(destinationPath, content, 'utf-8')
await writeFile(destinationPath, content, 'utf-8')
consola.success(`[valaxy new]: successfully generated file ${magenta(destinationPath)}`)
}
catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion packages/valaxy/node/cli/utils/scaffold.ts
@@ -1,5 +1,5 @@
import path from 'node:path'
import { readFile } from 'fs-extra'
import { readFile } from 'node:fs/promises'
import { resolveOptions } from '../../options'
import { exists } from './fs'
import { userRoot } from './constants'
Expand Down
2 changes: 1 addition & 1 deletion packages/valaxy/node/plugins/presets/statistics.ts
@@ -1,4 +1,4 @@
import { existsSync, readFileSync } from 'fs-extra'
import { existsSync, readFileSync } from 'node:fs'
import type { SiteConfig } from 'valaxy/types'
import type { ValaxyExtendConfig } from '../../types'

Expand Down
2 changes: 1 addition & 1 deletion packages/valaxy/node/plugins/unocss.ts
@@ -1,5 +1,5 @@
import { resolve } from 'node:path'
import { existsSync } from 'fs-extra'
import { existsSync } from 'node:fs'
import type { VitePluginConfig as UnoCSSConfig, VitePluginConfig } from 'unocss/vite'
import jiti from 'jiti'
import defu from 'defu'
Expand Down
4 changes: 1 addition & 3 deletions packages/valaxy/node/plugins/valaxy.ts
Expand Up @@ -6,10 +6,8 @@ import { join, relative, resolve } from 'node:path'
import fs from 'fs-extra'

import type { Plugin, ResolvedConfig } from 'vite'

// import consola from 'consola'
import { pascalCase } from 'change-case/dist'
import { defu } from 'defu'
import pascalCase from 'pascalcase'
import { defaultSiteConfig } from '../config'
import type { ResolvedValaxyOptions, ValaxyServerOptions } from '../options'
import { processValaxyOptions, resolveOptions, resolveThemeValaxyConfig } from '../options'
Expand Down
8 changes: 5 additions & 3 deletions packages/valaxy/package.json
Expand Up @@ -39,7 +39,7 @@
"vala": "./bin/valaxy.cjs",
"valac": "./bin/valaxy.cjs",
"valam": "./bin/valaxy.mjs",
"valaxy": "./bin/valaxy.cjs"
"valaxy": "./bin/valaxy.mjs"
},
"files": [
"bin",
Expand Down Expand Up @@ -70,7 +70,6 @@
"@vueuse/integrations": "^10.4.1",
"@vueuse/schema-org": "^2.2.0",
"body-scroll-lock": "4.0.0-beta.0",
"change-case": "^5.0.1",
"consola": "^3.2.3",
"critters": "^0.0.20",
"cross-spawn": "^7.0.3",
Expand All @@ -79,6 +78,7 @@
"ejs": "^3.1.9",
"escape-html": "^1.0.3",
"feed": "^4.2.2",
"fs-extra": "^11.1.1",
"fuse.js": "^6.6.2",
"global-dirs": "^3.0.1",
"gray-matter": "^4.0.3",
Expand All @@ -97,7 +97,8 @@
"markdown-it-task-lists": "^2.1.1",
"medium-zoom": "^1.0.8",
"nprogress": "^0.2.0",
"open": "8.4.2",
"open": "9.1.0",
"pascalcase": "^2.0.0",
"pinia": "^2.1.6",
"sass": "^1.68.0",
"shiki": "^0.14.4",
Expand Down Expand Up @@ -130,6 +131,7 @@
"@types/katex": "^0.16.3",
"@types/markdown-it": "^13.0.2",
"@types/nprogress": "^0.2.1",
"@types/pascalcase": "^1.0.1",
"@types/yargs": "^17.0.26",
"debug": "^4.3.4",
"diacritics": "^1.3.0",
Expand Down
16 changes: 16 additions & 0 deletions packages/valaxy/tsup.config.ts
Expand Up @@ -25,5 +25,21 @@ export default defineConfig((options) => {
js: `.${format === 'esm' ? 'mjs' : 'cjs'}`,
}
},

/**
* @see https://tsup.egoist.dev/#inject-cjs-and-esm-shims
* shim for __filename
*/
shims: true,
/**
* @see https://github.com/egoist/tsup/discussions/505
*/
banner: ({ format }) => {
if (format === 'esm') {
return {
js: `import {createRequire as __createRequire} from 'module';var require=__createRequire(import\.meta.url);`,
}
}
},
}
})

2 comments on commit 74ed01c

@vercel
Copy link

@vercel vercel bot commented on 74ed01c Oct 2, 2023

Choose a reason for hiding this comment

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

@github-actions
Copy link

Choose a reason for hiding this comment

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

🎉 Published on https://yun.valaxy.site as production
🚀 Deployed on https://651afdc8952c52524f3e1258--valaxy.netlify.app

Please sign in to comment.