Skip to content

Commit

Permalink
fix: remove __dirname CJS references
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed Sep 10, 2023
1 parent 923193f commit db37b2b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,11 @@ Create a `kirbyup.config.js` or `kirbyup.config.ts` configuration file the root-
import { resolve } from 'node:path'
import { defineConfig } from 'kirbyup/config'

const currentDir = new URL('.', import.meta.url).pathname

export default defineConfig({
alias: {
'#deep/': `${resolve(__dirname, 'src/deep')}/`
'#deep/': `${resolve(currentDir, 'src/deep')}/`
},
extendViteConfig: {
build: {
Expand Down
12 changes: 8 additions & 4 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { remove } from 'fs-extra'
import { afterAll, beforeAll, expect, it, vi } from 'vitest'
import { cacheDir, runCli } from './utils'

const currentDir = new URL('.', import.meta.url).pathname

beforeAll(async () => {
// unset so kirbyup applies its default env setting
vi.stubEnv('NODE_ENV', '')
Expand Down Expand Up @@ -133,7 +135,7 @@ it('compiles vue templates', async () => {
it('supports auto-importing components', async () => {
const { output } = await runCli({
'src/input.js': `
import { kirbyup } from '${resolve(__dirname, '../dist/plugin.mjs')}'
import { kirbyup } from '${resolve(currentDir, '../dist/client/plugin.mjs')}'
window.panel.plugin('kirbyup/example', {
blocks: kirbyup.import('./components/blocks/*.vue')
Expand All @@ -152,9 +154,10 @@ it('supports kirbyup.config.js with object', async () => {
'src/foo.js': 'export default \'bar\'',
'kirbyup.config.js': `
import { resolve } from 'path'
const currentDir = new URL('.', import.meta.url).pathname
export default {
alias: {
'__ALIAS__/': resolve(__dirname, 'src') + '/'
'__ALIAS__/': resolve(currentDir, 'src') + '/'
},
extendViteConfig: {
build: {
Expand All @@ -176,10 +179,11 @@ it('supports kirbyup.config.js with function', async () => {
'src/foo.js': 'export default \'bar\'',
'kirbyup.config.js': `
import { resolve } from 'path'
import { defineConfig } from '${resolve(__dirname, '../dist/config.mjs')}'
import { defineConfig } from '${resolve(currentDir, '../dist/client/config.mjs')}'
const currentDir = new URL('.', import.meta.url).pathname
export default defineConfig({
alias: {
'__ALIAS__/': resolve(__dirname, 'src') + '/'
'__ALIAS__/': resolve(currentDir, 'src') + '/'
},
extendViteConfig: {
build: {
Expand Down
4 changes: 2 additions & 2 deletions test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { outputFile, readFile } from 'fs-extra'
import fg from 'fast-glob'
import { startCli } from '../src/node/cli-start'

export const cacheDir = resolve(__dirname, '.cache')
export const cli = resolve(__dirname, '../src/node/cli.ts')
export const cacheDir = new URL('./.cache', import.meta.url).pathname
export const cli = new URL('../src/node/cli.ts', import.meta.url).pathname

export async function runCli(files: Record<string, string>) {
const testDir = resolve(cacheDir, Date.now().toString())
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "node",
"moduleResolution": "Node",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
Expand Down

0 comments on commit db37b2b

Please sign in to comment.