Skip to content

Commit

Permalink
fix(generators): Use cross-platform ES module __dirname (#3402)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl authored Jan 24, 2024
1 parent 473d028 commit 0ac4882
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 8 deletions.
3 changes: 2 additions & 1 deletion packages/generators/src/app/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { sep, dirname } from 'path'
import chalk from 'chalk'
import { prompt, runGenerators, fromFile, copyFiles, toFile } from '@featherscloud/pinion'
import { fileURLToPath } from 'url'
import {
FeathersBaseContext,
FeathersAppInfo,
Expand All @@ -11,7 +12,7 @@ import {
import { generate as connectionGenerator, prompts as connectionPrompts } from '../connection/index.js'

// Set __dirname in es module
const __dirname = dirname(new URL(import.meta.url).pathname)
const __dirname = dirname(fileURLToPath(import.meta.url))

export interface AppGeneratorData extends FeathersAppInfo {
/**
Expand Down
3 changes: 2 additions & 1 deletion packages/generators/src/authentication/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import chalk from 'chalk'
import { dirname } from 'path'
import { runGenerators, prompt } from '@featherscloud/pinion'
import { fileURLToPath } from 'url'
import {
addVersions,
checkPreconditions,
Expand All @@ -11,7 +12,7 @@ import {
import { generate as serviceGenerator, ServiceGeneratorContext } from '../service/index.js'

// Set __dirname in es module
const __dirname = dirname(new URL(import.meta.url).pathname)
const __dirname = dirname(fileURLToPath(import.meta.url))

export interface AuthenticationGeneratorContext extends ServiceGeneratorContext {
service: string
Expand Down
3 changes: 2 additions & 1 deletion packages/generators/src/commons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ import {
import ts from 'typescript'
import prettier, { Options as PrettierOptions } from 'prettier'
import path from 'path'
import { fileURLToPath } from 'url'

// Set __dirname in es module
const __dirname = dirname(new URL(import.meta.url).pathname)
const __dirname = dirname(fileURLToPath(import.meta.url))

export const { version } = JSON.parse(fs.readFileSync(join(__dirname, '..', 'package.json')).toString())

Expand Down
3 changes: 2 additions & 1 deletion packages/generators/src/connection/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { dirname } from 'path'
import { runGenerator, prompt, mergeJSON, toFile, when } from '@featherscloud/pinion'
import { fileURLToPath } from 'url'
import chalk from 'chalk'
import {
install,
Expand All @@ -12,7 +13,7 @@ import {
} from '../commons.js'

// Set __dirname in es module
const __dirname = dirname(new URL(import.meta.url).pathname)
const __dirname = dirname(fileURLToPath(import.meta.url))

export interface ConnectionGeneratorContext extends FeathersBaseContext {
name?: string
Expand Down
3 changes: 2 additions & 1 deletion packages/generators/src/hook/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { dirname } from 'path'
import { fileURLToPath } from 'url'
import { prompt, runGenerators } from '@featherscloud/pinion'
import _ from 'lodash'
import { checkPreconditions, FeathersBaseContext, initializeBaseContext } from '../commons.js'

// Set __dirname in es module
const __dirname = dirname(new URL(import.meta.url).pathname)
const __dirname = dirname(fileURLToPath(import.meta.url))

export interface HookGeneratorContext extends FeathersBaseContext {
name: string
Expand Down
7 changes: 4 additions & 3 deletions packages/generators/src/service/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { dirname } from 'path'
import _ from 'lodash'
import { runGenerator, runGenerators, prompt } from '@featherscloud/pinion'
import { fileURLToPath } from 'url'
import chalk from 'chalk'

// Set __dirname in es module
const __dirname = dirname(new URL(import.meta.url).pathname)

import {
checkPreconditions,
DATABASE_TYPES,
Expand All @@ -15,6 +13,9 @@ import {
initializeBaseContext
} from '../commons.js'

// Set __dirname in es module
const __dirname = dirname(fileURLToPath(import.meta.url))

export interface ServiceGeneratorContext extends FeathersBaseContext {
/**
* The chosen service name
Expand Down

0 comments on commit 0ac4882

Please sign in to comment.