Skip to content

Commit

Permalink
fix(migrate): seed with ts-node - remove declare const require (#7117)
Browse files Browse the repository at this point in the history
Original PR #6034
  • Loading branch information
Jolg42 committed May 17, 2021
1 parent eea9f78 commit 3fe52e4
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 21 deletions.
1 change: 1 addition & 0 deletions src/packages/migrate/package.json
Expand Up @@ -71,6 +71,7 @@
"strip-indent": "^3.0.0"
},
"scripts": {
"postinstall": "cd src/__tests__/fixtures/seed-sqlite && npm i && cd ../seed-sqlite-js-ts-default-export && npm i && cd ../seed-sqlite-js-ts-named-export && npm i",
"run": "node dist/bin.js",
"precommit": "lint-staged",
"format": "prettier --write .",
Expand Down
2 changes: 1 addition & 1 deletion src/packages/migrate/src/__tests__/DbSeed.test.ts
Expand Up @@ -244,7 +244,7 @@ describe('seed', () => {
})

it('Custom --schema from package.json', async () => {
ctx.fixture('seed-sqilte-schema-from-package-json')
ctx.fixture('seed-sqlite-schema-from-package-json')

const result = DbSeed.new().parse(['--preview-feature'])
await expect(result).resolves.toMatchInlineSnapshot(`
Expand Down
Expand Up @@ -6,9 +6,7 @@
},
"license": "MIT",
"devDependencies": {
"@types/node": "^14.14.21",
"ts-node": "^9.1.1",
"typescript": "^4.1.3"
"@types/node": "^14.14.21"
},
"engines": {
"node": ">=10.4"
Expand Down
@@ -1,11 +1,9 @@
{
"name": "seed-sqlite",
"name": "seed-sqlite-js-ts-default-export",
"version": "1.0.0",
"license": "MIT",
"devDependencies": {
"@types/node": "^14.14.21",
"ts-node": "^9.1.1",
"typescript": "^4.1.3"
"@types/node": "^14.14.21"
},
"engines": {
"node": ">=10.4"
Expand Down
@@ -1,11 +1,9 @@
{
"name": "seed-sqlite",
"name": "seed-sqlite-js-ts-named-export",
"version": "1.0.0",
"license": "MIT",
"devDependencies": {
"@types/node": "^14.14.21",
"ts-node": "^9.1.1",
"typescript": "^4.1.3"
"@types/node": "^14.14.21"
},
"engines": {
"node": ">=10.4"
Expand Down
Expand Up @@ -3,9 +3,7 @@
"version": "1.0.0",
"license": "MIT",
"devDependencies": {
"@types/node": "^14.14.21",
"ts-node": "^9.1.1",
"typescript": "^4.1.3"
"@types/node": "^14.14.21"
},
"engines": {
"node": ">=10.4"
Expand Down
8 changes: 2 additions & 6 deletions src/packages/migrate/src/utils/seed.ts
Expand Up @@ -68,7 +68,7 @@ export function detectSeedFiles(schemaPath) {
}

function getSeedScript(type: 'TS' | 'JS', seedFilepath: string) {
let script = `
const script = `
const __seed = require('./${seedFilepath}')
const __keys = Object.keys(__seed)
Expand All @@ -83,10 +83,6 @@ function getSeedScript(type: 'TS' | 'JS', seedFilepath: string) {
''
}`

if (type === 'TS') {
script = 'declare const require: any' + script
}

return script
}

Expand Down Expand Up @@ -146,7 +142,7 @@ To install them run: ${chalk.green(
// Check package.json for a "ts-node" script (so users can customize flags)
const scripts = await getScriptsFromPackageJson()
let tsNodeCommand = `ts-node`
let tsNodeArgs = `-p -e "${getSeedScript('TS', detected.ts)}"`
let tsNodeArgs = `--print --eval "${getSeedScript('TS', detected.ts)}"`

// User can customize the `ts-node` command from the package script
if (scripts?.['ts-node']) {
Expand Down

0 comments on commit 3fe52e4

Please sign in to comment.