-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(gatsby): show meaningful error message when engines try to bundle…
… ts-node (#35762) Co-authored-by: Lennart <lekoarts@gmail.com>
- Loading branch information
Showing
4 changed files
with
171 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/gatsby/src/schema/graphql-engine/shims/ts-node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export function register() { | ||
// no-op | ||
// | ||
// We are actually failing the build when `ts-node` exists in webpack's dependency graph | ||
// because it's known to not work and cause failures. | ||
// | ||
// This shim for `ts-node` just skips trying to bundle the actual `ts-node` | ||
// so webpack has less work to do during bundling. | ||
// | ||
// Using or not this shim, functionally doesn't make a difference - we will still | ||
// fail the build with same actionable error anyway. | ||
} |
70 changes: 70 additions & 0 deletions
70
packages/gatsby/src/schema/graphql-engine/standalone-regenerate.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/usr/bin/env node | ||
|
||
/* | ||
this is used for development purposes only | ||
to be able to run `gatsby build` once to source data | ||
and print schema and then just rebundle graphql-engine | ||
with source file changes and test re-built engine quickly | ||
Usage: | ||
There need to be at least one successful `gatsby build` | ||
before starting to use this script (warm up datastore, | ||
generate "page-ssr" bundle). Once that's done you can | ||
run following command in test site directory: | ||
```shell | ||
node node_modules/gatsby/dist/schema/graphql-engine/standalone-regenerate.js | ||
``` | ||
*/ | ||
|
||
import { createGraphqlEngineBundle } from "./bundle-webpack" | ||
import reporter from "gatsby-cli/lib/reporter" | ||
import { loadConfigAndPlugins } from "../../utils/worker/child/load-config-and-plugins" | ||
import * as fs from "fs-extra" | ||
import { validateEngines } from "../../utils/validate-engines" | ||
|
||
async function run(): Promise<void> { | ||
// load config | ||
console.log(`loading config and plugins`) | ||
await loadConfigAndPlugins({ | ||
siteDirectory: process.cwd(), | ||
}) | ||
|
||
try { | ||
console.log(`clearing webpack cache\n\n`) | ||
// get rid of cache if it exist | ||
await fs.remove(process.cwd() + `/.cache/webpack/query-engine`) | ||
} catch (e) { | ||
// eslint-disable no-empty | ||
} | ||
|
||
// recompile | ||
const buildActivityTimer = reporter.activityTimer( | ||
`Building Rendering Engines` | ||
) | ||
try { | ||
buildActivityTimer.start() | ||
await createGraphqlEngineBundle(process.cwd(), reporter, true) | ||
} catch (err) { | ||
buildActivityTimer.panic(err) | ||
} finally { | ||
buildActivityTimer.end() | ||
} | ||
|
||
// validate | ||
const validateEnginesActivity = reporter.activityTimer( | ||
`Validating Rendering Engines` | ||
) | ||
validateEnginesActivity.start() | ||
try { | ||
await validateEngines(process.cwd()) | ||
} catch (error) { | ||
validateEnginesActivity.panic({ id: `98001`, context: {}, error }) | ||
} finally { | ||
validateEnginesActivity.end() | ||
} | ||
|
||
console.log(`DONE`) | ||
} | ||
|
||
run() |