diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b0989df..8992bda 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,6 +8,9 @@ on: push: branches: - main + - next + - alpha + - beta jobs: release: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bac6448..4e4d384 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,6 +7,9 @@ on: pull_request: branches: - main + - next + - alpha + - beta workflow_dispatch: jobs: diff --git a/package.json b/package.json index 2076404..cf1bf83 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,8 @@ "ls:pack": "npm pack --dry-run", "prepare": "ts-patch install -s", "preinstall": "npx only-allow pnpm", - "semantic-release": "semantic-release" + "semantic-release": "semantic-release", + "sync": "cnpm sync weapp-pandacss" }, "packageManager": "pnpm@8.6.9", "repository": { @@ -113,17 +114,17 @@ "outdent": "^0.8.0", "postcss": "^8.4.27", "prettier": "^3.0.0", - "rollup": "^3.26.3", + "rollup": "^3.27.0", "rollup-plugin-visualizer": "^5.9.2", "semantic-release": "^21.0.7", + "semver": "^7.5.4", "ts-node": "^10.9.1", "ts-patch": "^3.0.2", "tsconfig-paths": "^4.2.0", "tslib": "^2.6.1", "typescript": "^5.1.6", "typescript-transform-paths": "^3.4.6", - "vitest": "^0.33.0", - "semver": "^7.5.4" + "vitest": "^0.33.0" }, "dependencies": { "@babel/generator": "^7.22.9", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 207a6ac..de7767a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -36,28 +36,28 @@ dependencies: devDependencies: '@pandacss/dev': specifier: ^0.8.0 - version: 0.8.0(@internationalized/date@3.3.0)(@types/node@20.4.5)(@types/react-dom@18.2.7)(@types/react@18.2.17)(astro@2.9.4)(ts-node@10.9.1)(typescript@5.1.6) + version: 0.8.0(@internationalized/date@3.3.0)(@types/node@20.4.5)(@types/react-dom@18.2.7)(@types/react@18.2.17)(astro@2.9.5)(ts-node@10.9.1)(typescript@5.1.6) '@rollup/plugin-alias': specifier: ^5.0.0 - version: 5.0.0(rollup@3.26.3) + version: 5.0.0(rollup@3.27.0) '@rollup/plugin-commonjs': specifier: ^25.0.3 - version: 25.0.3(rollup@3.26.3) + version: 25.0.3(rollup@3.27.0) '@rollup/plugin-json': specifier: ^6.0.0 - version: 6.0.0(rollup@3.26.3) + version: 6.0.0(rollup@3.27.0) '@rollup/plugin-node-resolve': specifier: ^15.1.0 - version: 15.1.0(rollup@3.26.3) + version: 15.1.0(rollup@3.27.0) '@rollup/plugin-replace': specifier: ^5.0.2 - version: 5.0.2(rollup@3.26.3) + version: 5.0.2(rollup@3.27.0) '@rollup/plugin-terser': specifier: ^0.4.3 - version: 0.4.3(rollup@3.26.3) + version: 0.4.3(rollup@3.27.0) '@rollup/plugin-typescript': specifier: ^11.1.2 - version: 11.1.2(rollup@3.26.3)(tslib@2.6.1)(typescript@5.1.6) + version: 11.1.2(rollup@3.27.0)(tslib@2.6.1)(typescript@5.1.6) '@tsconfig/recommended': specifier: ^1.0.2 version: 1.0.2 @@ -137,11 +137,11 @@ devDependencies: specifier: ^3.0.0 version: 3.0.0 rollup: - specifier: ^3.26.3 - version: 3.26.3 + specifier: ^3.27.0 + version: 3.27.0 rollup-plugin-visualizer: specifier: ^5.9.2 - version: 5.9.2(rollup@3.26.3) + version: 5.9.2(rollup@3.27.0) semantic-release: specifier: ^21.0.7 version: 21.0.7 @@ -279,13 +279,13 @@ packages: - supports-color dev: true - /@astrojs/markdown-remark@2.2.1(astro@2.9.4): + /@astrojs/markdown-remark@2.2.1(astro@2.9.5): resolution: {integrity: sha512-VF0HRv4GpC1XEMLnsKf6jth7JSmlt9qpqP0josQgA2eSpCIAC/Et+y94mgdBIZVBYH/yFnMoIxgKVe93xfO2GA==} peerDependencies: astro: ^2.5.0 dependencies: '@astrojs/prism': 2.1.2 - astro: 2.9.4(@types/node@20.4.5) + astro: 2.9.5(@types/node@20.4.5) github-slugger: 1.5.0 import-meta-resolve: 2.2.2 rehype-raw: 6.1.1 @@ -1278,13 +1278,13 @@ packages: '@octokit/openapi-types': 18.0.0 dev: true - /@pandacss/astro@0.8.0(astro@2.9.4)(ts-node@10.9.1)(typescript@5.1.6): + /@pandacss/astro@0.8.0(astro@2.9.5)(ts-node@10.9.1)(typescript@5.1.6): resolution: {integrity: sha512-XoZcR4TL3RKoTvH643pRuVC3RT23nNBt/zj0UTDZpsVF83bvLVbqtwvU0/Bmbt5SJFn04vr62ZqPT2ctur+FeA==} peerDependencies: astro: '>=2.x' dependencies: '@pandacss/postcss': 0.8.0(typescript@5.1.6) - astro: 2.9.4(@types/node@20.4.5) + astro: 2.9.5(@types/node@20.4.5) autoprefixer: 10.4.14(postcss@8.4.27) postcss: 8.4.27 postcss-load-config: 4.0.1(postcss@8.4.27)(ts-node@10.9.1) @@ -1329,7 +1329,7 @@ packages: ts-pattern: 5.0.4 dev: true - /@pandacss/dev@0.8.0(@internationalized/date@3.3.0)(@types/node@20.4.5)(@types/react-dom@18.2.7)(@types/react@18.2.17)(astro@2.9.4)(ts-node@10.9.1)(typescript@5.1.6): + /@pandacss/dev@0.8.0(@internationalized/date@3.3.0)(@types/node@20.4.5)(@types/react-dom@18.2.7)(@types/react@18.2.17)(astro@2.9.5)(ts-node@10.9.1)(typescript@5.1.6): resolution: {integrity: sha512-3mG4w6gcrkPZ/QMpwmBnRyi7/9GaBs5vK3z3/v1JOU7w/JHOR2nA5WmScanW5gDfImogxwT7WuHguYKCUP+E6g==} hasBin: true peerDependencies: @@ -1338,7 +1338,7 @@ packages: astro: optional: true dependencies: - '@pandacss/astro': 0.8.0(astro@2.9.4)(ts-node@10.9.1)(typescript@5.1.6) + '@pandacss/astro': 0.8.0(astro@2.9.5)(ts-node@10.9.1)(typescript@5.1.6) '@pandacss/config': 0.8.0 '@pandacss/error': 0.8.0 '@pandacss/logger': 0.8.0 @@ -1349,7 +1349,7 @@ packages: '@pandacss/studio': 0.8.0(@internationalized/date@3.3.0)(@types/node@20.4.5)(@types/react-dom@18.2.7)(@types/react@18.2.17)(typescript@5.1.6) '@pandacss/token-dictionary': 0.8.0 '@pandacss/types': 0.8.0 - astro: 2.9.4(@types/node@20.4.5) + astro: 2.9.5(@types/node@20.4.5) cac: 6.7.14 pathe: 1.1.1 perfect-debounce: 1.0.0 @@ -1572,7 +1572,7 @@ packages: config-chain: 1.1.13 dev: true - /@rollup/plugin-alias@5.0.0(rollup@3.26.3): + /@rollup/plugin-alias@5.0.0(rollup@3.27.0): resolution: {integrity: sha512-l9hY5chSCjuFRPsnRm16twWBiSApl2uYFLsepQYwtBuAxNMQ/1dJqADld40P0Jkqm65GRTLy/AC6hnpVebtLsA==} engines: {node: '>=14.0.0'} peerDependencies: @@ -1581,11 +1581,11 @@ packages: rollup: optional: true dependencies: - rollup: 3.26.3 + rollup: 3.27.0 slash: 4.0.0 dev: true - /@rollup/plugin-commonjs@25.0.3(rollup@3.26.3): + /@rollup/plugin-commonjs@25.0.3(rollup@3.27.0): resolution: {integrity: sha512-uBdtWr/H3BVcgm97MUdq2oJmqBR23ny1hOrWe2PKo9FTbjsGqg32jfasJUKYAI5ouqacjRnj65mBB/S79F+GQA==} engines: {node: '>=14.0.0'} peerDependencies: @@ -1594,16 +1594,16 @@ packages: rollup: optional: true dependencies: - '@rollup/pluginutils': 5.0.2(rollup@3.26.3) + '@rollup/pluginutils': 5.0.2(rollup@3.27.0) commondir: 1.0.1 estree-walker: 2.0.2 glob: 8.1.0 is-reference: 1.2.1 magic-string: 0.27.0 - rollup: 3.26.3 + rollup: 3.27.0 dev: true - /@rollup/plugin-json@6.0.0(rollup@3.26.3): + /@rollup/plugin-json@6.0.0(rollup@3.27.0): resolution: {integrity: sha512-i/4C5Jrdr1XUarRhVu27EEwjt4GObltD7c+MkCIpO2QIbojw8MUs+CCTqOphQi3Qtg1FLmYt+l+6YeoIf51J7w==} engines: {node: '>=14.0.0'} peerDependencies: @@ -1612,11 +1612,11 @@ packages: rollup: optional: true dependencies: - '@rollup/pluginutils': 5.0.2(rollup@3.26.3) - rollup: 3.26.3 + '@rollup/pluginutils': 5.0.2(rollup@3.27.0) + rollup: 3.27.0 dev: true - /@rollup/plugin-node-resolve@15.1.0(rollup@3.26.3): + /@rollup/plugin-node-resolve@15.1.0(rollup@3.27.0): resolution: {integrity: sha512-xeZHCgsiZ9pzYVgAo9580eCGqwh/XCEUM9q6iQfGNocjgkufHAqC3exA+45URvhiYV8sBF9RlBai650eNs7AsA==} engines: {node: '>=14.0.0'} peerDependencies: @@ -1625,16 +1625,16 @@ packages: rollup: optional: true dependencies: - '@rollup/pluginutils': 5.0.2(rollup@3.26.3) + '@rollup/pluginutils': 5.0.2(rollup@3.27.0) '@types/resolve': 1.20.2 deepmerge: 4.3.1 is-builtin-module: 3.2.1 is-module: 1.0.0 resolve: 1.22.2 - rollup: 3.26.3 + rollup: 3.27.0 dev: true - /@rollup/plugin-replace@5.0.2(rollup@3.26.3): + /@rollup/plugin-replace@5.0.2(rollup@3.27.0): resolution: {integrity: sha512-M9YXNekv/C/iHHK+cvORzfRYfPbq0RDD8r0G+bMiTXjNGKulPnCT9O3Ss46WfhI6ZOCgApOP7xAdmCQJ+U2LAA==} engines: {node: '>=14.0.0'} peerDependencies: @@ -1643,12 +1643,12 @@ packages: rollup: optional: true dependencies: - '@rollup/pluginutils': 5.0.2(rollup@3.26.3) + '@rollup/pluginutils': 5.0.2(rollup@3.27.0) magic-string: 0.27.0 - rollup: 3.26.3 + rollup: 3.27.0 dev: true - /@rollup/plugin-terser@0.4.3(rollup@3.26.3): + /@rollup/plugin-terser@0.4.3(rollup@3.27.0): resolution: {integrity: sha512-EF0oejTMtkyhrkwCdg0HJ0IpkcaVg1MMSf2olHb2Jp+1mnLM04OhjpJWGma4HobiDTF0WCyViWuvadyE9ch2XA==} engines: {node: '>=14.0.0'} peerDependencies: @@ -1657,13 +1657,13 @@ packages: rollup: optional: true dependencies: - rollup: 3.26.3 + rollup: 3.27.0 serialize-javascript: 6.0.1 smob: 1.0.0 terser: 5.17.4 dev: true - /@rollup/plugin-typescript@11.1.2(rollup@3.26.3)(tslib@2.6.1)(typescript@5.1.6): + /@rollup/plugin-typescript@11.1.2(rollup@3.27.0)(tslib@2.6.1)(typescript@5.1.6): resolution: {integrity: sha512-0ghSOCMcA7fl1JM+0gYRf+Q/HWyg+zg7/gDSc+fRLmlJWcW5K1I+CLRzaRhXf4Y3DRyPnnDo4M2ktw+a6JcDEg==} engines: {node: '>=14.0.0'} peerDependencies: @@ -1676,14 +1676,14 @@ packages: tslib: optional: true dependencies: - '@rollup/pluginutils': 5.0.2(rollup@3.26.3) + '@rollup/pluginutils': 5.0.2(rollup@3.27.0) resolve: 1.22.2 - rollup: 3.26.3 + rollup: 3.27.0 tslib: 2.6.1 typescript: 5.1.6 dev: true - /@rollup/pluginutils@5.0.2(rollup@3.26.3): + /@rollup/pluginutils@5.0.2(rollup@3.27.0): resolution: {integrity: sha512-pTd9rIsP92h+B6wWwFbW8RkZv4hiR/xKsqre4SIuAOaOEQRxi0lqLke9k2/7WegC85GgUs9pjmOjCUi3In4vwA==} engines: {node: '>=14.0.0'} peerDependencies: @@ -1695,7 +1695,7 @@ packages: '@types/estree': 1.0.1 estree-walker: 2.0.2 picomatch: 2.3.1 - rollup: 3.26.3 + rollup: 3.27.0 dev: true /@semantic-release/commit-analyzer@10.0.1(semantic-release@21.0.7): @@ -3088,8 +3088,8 @@ packages: - terser dev: true - /astro@2.9.4(@types/node@20.4.5): - resolution: {integrity: sha512-6mIAFTkfrLn1aAOVO7clTz3NqJNyPdJXLZEkAFTl+s5iuaIdoYnuqItkcjWP1qoEeGPF+0w9rTr0388pkTK+lg==} + /astro@2.9.5(@types/node@20.4.5): + resolution: {integrity: sha512-F9qi3TzNfnl4wN3ufVRz13lX30krUd6FcEmP5gxFR3pjxk2a6+CghOZP/AgZ077Ws0RSpow29xtMhTSP7J6auQ==} engines: {node: '>=16.12.0', npm: '>=6.14.0'} hasBin: true peerDependencies: @@ -3101,7 +3101,7 @@ packages: '@astrojs/compiler': 1.6.3 '@astrojs/internal-helpers': 0.1.1 '@astrojs/language-server': 1.0.8 - '@astrojs/markdown-remark': 2.2.1(astro@2.9.4) + '@astrojs/markdown-remark': 2.2.1(astro@2.9.5) '@astrojs/telemetry': 2.1.1 '@astrojs/webapi': 2.2.0 '@babel/core': 7.22.9 @@ -7438,7 +7438,7 @@ packages: glob: 7.2.3 dev: true - /rollup-plugin-visualizer@5.9.2(rollup@3.26.3): + /rollup-plugin-visualizer@5.9.2(rollup@3.27.0): resolution: {integrity: sha512-waHktD5mlWrYFrhOLbti4YgQCn1uR24nYsNuXxg7LkPH8KdTXVWR9DNY1WU0QqokyMixVXJS4J04HNrVTMP01A==} engines: {node: '>=14'} hasBin: true @@ -7450,13 +7450,13 @@ packages: dependencies: open: 8.4.2 picomatch: 2.3.1 - rollup: 3.26.3 + rollup: 3.27.0 source-map: 0.7.4 yargs: 17.7.2 dev: true - /rollup@3.26.3: - resolution: {integrity: sha512-7Tin0C8l86TkpcMtXvQu6saWH93nhG3dGQ1/+l5V2TDMceTxO7kDiK6GzbfLWNNxqJXm591PcEZUozZm51ogwQ==} + /rollup@3.27.0: + resolution: {integrity: sha512-aOltLCrYZ0FhJDm7fCqwTjIUEVjWjcydKBV/Zeid6Mn8BWgDCUBBWT5beM5ieForYNo/1ZHuGJdka26kvQ3Gzg==} engines: {node: '>=14.18.0', npm: '>=8.0.0'} hasBin: true optionalDependencies: @@ -8531,7 +8531,7 @@ packages: '@types/node': 20.4.5 esbuild: 0.17.19 postcss: 8.4.27 - rollup: 3.26.3 + rollup: 3.27.0 optionalDependencies: fsevents: 2.3.2 dev: true @@ -8567,7 +8567,7 @@ packages: '@types/node': 20.4.5 esbuild: 0.18.17 postcss: 8.4.27 - rollup: 3.26.3 + rollup: 3.27.0 optionalDependencies: fsevents: 2.3.2 dev: true @@ -8603,7 +8603,7 @@ packages: '@types/node': 20.4.5 esbuild: 0.18.17 postcss: 8.4.27 - rollup: 3.26.3 + rollup: 3.27.0 optionalDependencies: fsevents: 2.3.2 dev: true diff --git a/src/core/context.ts b/src/core/context.ts index a25c683..f5c7c0a 100644 --- a/src/core/context.ts +++ b/src/core/context.ts @@ -13,12 +13,12 @@ export async function createContext(options?: ICreateContextOptions) { const opt = defu(options, getCreateContextDefaults()) const pandaConfig = await getPandacssConfig(opt.pandaConfig) - + const outdir = pandaConfig.config.outdir + const projectRoot = dirname(pandaConfig.path) async function codegen() { const words: string[] = [] - const outdir = pandaConfig.config.outdir - const weappPandaDir = resolve(outdir, 'weapp-panda') - const patchHelpersPath = resolve(outdir, 'helpers.mjs') + const weappPandaDir = resolve(projectRoot, outdir, 'weapp-panda') + const patchHelpersPath = resolve(projectRoot, outdir, 'helpers.mjs') await copyEscape(weappPandaDir) words.push(dedent` ${tick} ${quote(outdir, '/weapp-panda')}: the core escape function for weapp @@ -41,8 +41,11 @@ export async function createContext(options?: ICreateContextOptions) { } async function rollback() { - const outdir = pandaConfig.config.outdir - const patchHelpersBackupPath = resolve(outdir, '_helpers.backup.mjs') + const patchHelpersBackupPath = resolve( + projectRoot, + outdir, + '_helpers.backup.mjs' + ) if (existsSync(patchHelpersBackupPath)) { await fs.copyFile( patchHelpersBackupPath, diff --git a/test/context.test.ts b/test/context.test.ts new file mode 100644 index 0000000..5f3a94d --- /dev/null +++ b/test/context.test.ts @@ -0,0 +1,39 @@ +import { copyFile, readFile } from 'node:fs/promises' +import { existsSync } from 'node:fs' +import { dirname, resolve } from 'node:path' +import { appRoot } from './util' +import { createContext } from '@/core/context' +import { ensureDir } from '@/core/codegen' + +describe('context', () => { + it('no config', async () => { + // expect(ctx).toBeDefined() + await expect(() => { + return createContext() + }).rejects.toThrowError() + }) + + it('with config in app', async () => { + const ctx = await createContext({ + pandaConfig: { + cwd: appRoot + } + }) + expect(ctx).toBeDefined() + expect(ctx.codegen).toBeDefined() + expect(ctx.pandaConfig).toBeDefined() + expect(ctx.rollback).toBeDefined() + const src = resolve(appRoot, 'src/styled-system/helpers.mjs') + await ensureDir(dirname(src)) + await copyFile(resolve(appRoot, 'styled-system/helpers.mjs'), src) + await ctx.codegen() + const backup = resolve(appRoot, 'src/styled-system/_helpers.backup.mjs') + existsSync(src) + existsSync(backup) + expect(await readFile(src, 'utf8')).not.toEqual( + await readFile(backup, 'utf8') + ) + await ctx.rollback() + expect(await readFile(src, 'utf8')).toEqual(await readFile(backup, 'utf8')) + }) +}) diff --git a/test/defaults.test.ts b/test/defaults.test.ts new file mode 100644 index 0000000..e11c443 --- /dev/null +++ b/test/defaults.test.ts @@ -0,0 +1,18 @@ +import { getCreateContextDefaults, getPostcssPluginDefaults } from '@/defaults' + +describe('defaults', () => { + it('getCreateContextDefaults', () => { + const config = getCreateContextDefaults() + expect(config).toBeDefined() + expect(config.pandaConfig).toBeDefined() + expect(config.pandaConfig.cwd).toBeDefined() + expect(config.pandaConfig.cwd).toBe(process.cwd()) + }) + + it('getPostcssPluginDefaults', () => { + const { cascadeLayersSelectorReplacement, universalSelectorReplacement } = + getPostcssPluginDefaults() + expect(cascadeLayersSelectorReplacement).toBeDefined() + expect(universalSelectorReplacement).toBeDefined() + }) +}) diff --git a/test/fixtures/app/.gitignore b/test/fixtures/app/.gitignore index b865a9d..e59529e 100644 --- a/test/fixtures/app/.gitignore +++ b/test/fixtures/app/.gitignore @@ -1 +1,2 @@ -weapp-panda \ No newline at end of file +weapp-panda +src/** \ No newline at end of file diff --git a/test/postcss.test.ts b/test/postcss.test.ts index eb96827..fe65711 100644 --- a/test/postcss.test.ts +++ b/test/postcss.test.ts @@ -1,7 +1,7 @@ import fs from 'node:fs/promises' import { resolve } from 'node:path' import postcss from 'postcss' -import parser from 'postcss-selector-parser' +// import parser from 'postcss-selector-parser' import { cssRoot } from './util' import postcssPlugin from '@/postcss' describe('postcss', () => { diff --git a/vitest.config.ts b/vitest.config.ts index 8ee9545..434f7aa 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -12,7 +12,7 @@ export default defineConfig({ globals: true, coverage: { enabled: true, - reportsDirectory: 'coverage/vitest' + include: ['src/**'] }, testTimeout: 60_000, setupFiles: ['./vitest.setup.ts']