Skip to content

Commit

Permalink
fix: yargs import for esm cli entry-point
Browse files Browse the repository at this point in the history
  • Loading branch information
tada5hi committed May 29, 2023
1 parent aa65095 commit 3d46dff
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 30 deletions.
88 changes: 74 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"license": "MIT",
"dependencies": {
"@faker-js/faker": "^8.0.2",
"locter": "^1.1.0",
"locter": "^1.1.2",
"pascal-case": "^3.1.2",
"rapiq": "^0.8.1",
"reflect-metadata": "^0.1.13",
Expand Down Expand Up @@ -90,7 +90,7 @@
"rollup": "^3.23.0",
"semantic-release": "^21.0.2",
"ts-jest": "^27.1.4",
"typeorm": "^0.3.15",
"typeorm": "^0.3.16",
"typescript": "^4.9.5",
"vitepress": "^1.0.0-beta.1",
"vue": "^3.2.47"
Expand Down
38 changes: 27 additions & 11 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import resolve from '@rollup/plugin-node-resolve';
import { transform } from "@swc/core";
import {transform} from "@swc/core";
import pkg from './package.json' assert {type: 'json'};
import path from "node:path";

Expand Down Expand Up @@ -42,15 +42,14 @@ const swc = () => {
}
}

const external = [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
/^typeorm/,
]
export default [
{
input: './src/cli/index.ts',
external,
external: [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
/^yargs/
],
plugins: [
{
resolveId(source, importer, options) {
Expand Down Expand Up @@ -80,7 +79,6 @@ export default [

// Compile TypeScript/JavaScript files
swc()

],
output: [
{
Expand All @@ -99,8 +97,11 @@ export default [

// Specify here external modules which you don't want to include in your bundle (for instance: 'lodash', 'moment' etc.)
// https://rollupjs.org/guide/en/#external
external,

external: [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
/^typeorm/,
],
plugins: [
// Allows node_modules resolution
resolve({ extensions}),
Expand All @@ -116,7 +117,22 @@ export default [
}, {
file: pkg.module,
format: 'esm',
sourcemap: true
sourcemap: true,
plugins: [
{
generateBundle(outputOptions, bundle, isWrite) {
for (const fileName in bundle) {
const chunk = bundle[fileName];
if (chunk.type === 'chunk') {
chunk.code = chunk.code.replace(
/import\s*{([\w\s,]+)}\s*from\s*(['"])typeorm([^'"]+)(['"])/g,
"import {$1} from $2typeorm$3.js$4"
);
}
}
}
}
]
}
]
}
Expand Down
7 changes: 4 additions & 3 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#!/usr/bin/env node
import 'reflect-metadata';
import process from 'node:process';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';

import {
DatabaseCreateCommand,
DatabaseDropCommand,
SeedCommand,
} from './commands';

// eslint-disable-next-line no-unused-expressions,@typescript-eslint/no-unused-expressions
yargs
yargs(hideBin(process.argv))
.scriptName('typeorm-extension')
.usage('Usage: $0 <command> [options]')
.demandCommand(1)
Expand All @@ -20,4 +21,4 @@ yargs
.alias('v', 'version')
.help('h')
.alias('h', 'help')
.argv;
.parse();

0 comments on commit 3d46dff

Please sign in to comment.