Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(migrate): seed with ts-node - remove declare const require #7117

Merged
merged 1 commit into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/packages/migrate/package.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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