-
Notifications
You must be signed in to change notification settings - Fork 65
feat: require all files that import nexus #833
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
Changes from all commits
9686229
9165334
f58c497
7f5d71d
f6112ef
e3749f4
6f53694
4d9ee53
11048ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ export class Dev implements Command { | |
} | ||
|
||
const entrypointPath = args['--entrypoint'] | ||
const reflectionMode = args['--reflection'] === true | ||
let layout = await Layout.create({ entrypointPath }) | ||
const pluginReflectionResult = await Reflection.reflect(layout, { usedPlugins: true, onMainThread: true }) | ||
|
||
|
@@ -73,6 +74,14 @@ export class Dev implements Command { | |
dev: { | ||
addToWatcherSettings: {}, | ||
async onBeforeWatcherStartOrRestart(change) { | ||
if (change.type === 'change') { | ||
const nexusModules = Layout.findNexusModules( | ||
layout.tsConfig, | ||
layout.app.exists ? layout.app.path : null | ||
) | ||
layout.update({ nexusModules }) | ||
Weakky marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
if ( | ||
change.type === 'init' || | ||
change.type === 'add' || | ||
|
@@ -89,36 +98,16 @@ export class Dev implements Command { | |
} | ||
|
||
runDebouncedReflection(layout) | ||
|
||
return { | ||
entrypointScript: getTranspiledStartModule(layout, reflectionMode), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So now before every restart the hook allows altering what entrypoint source is? Cool There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah. Makes me think it's dangerous to expose that on the plugin interface. Here, what this specifically enables is the ability to refresh the required schema modules in the start module whenever a file changes. This used to not be required because we were looking for schema modules based on the filenames. So recomputing the layout whenever a file was added/deleted was enough. But now that we find schema modules based on their import to Nexus, we need to recompute that on every file change. Here's a simple use-case where this is needed:
See, nexus modules are no longer tied to file creation/deletion anymore, but entirely based on their content |
||
} | ||
}, | ||
}, | ||
} | ||
|
||
const startModule = createStartModuleContent({ | ||
registerTypeScript: { | ||
...layout.tsConfig.content.options, | ||
module: ts.ModuleKind.CommonJS, | ||
target: ts.ScriptTarget.ES2015, | ||
}, | ||
internalStage: 'dev', | ||
runtimePluginManifests: [], // tree-shaking not needed | ||
layout, | ||
absoluteModuleImports: true, | ||
}) | ||
|
||
const transpiledStartModule = transpileModule(startModule, { | ||
...layout.tsConfig.content.options, | ||
module: ts.ModuleKind.CommonJS, | ||
target: ts.ScriptTarget.ES2015, | ||
}) | ||
|
||
/** | ||
* We use an empty script when in reflection mode so that the user's app doesn't run. | ||
* The watcher will keep running though and so will reflection in the devPlugin.onBeforeWatcherStartOrRestart hook above | ||
*/ | ||
const entrypointScript = args['--reflection'] ? '' : transpiledStartModule | ||
|
||
const watcher = await createWatcher({ | ||
entrypointScript, | ||
entrypointScript: getTranspiledStartModule(layout, reflectionMode), | ||
sourceRoot: layout.sourceRoot, | ||
cwd: process.cwd(), | ||
plugins: [devPlugin].concat(worktimePlugins.map((p) => p.hooks)), | ||
|
@@ -141,3 +130,31 @@ export class Dev implements Command { | |
` | ||
} | ||
} | ||
|
||
function getTranspiledStartModule(layout: Layout.Layout, reflectionMode: boolean) { | ||
Weakky marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/** | ||
* We use an empty script when in reflection mode so that the user's app doesn't run. | ||
* The watcher will keep running though and so will reflection in the devPlugin.onBeforeWatcherStartOrRestart hook above | ||
*/ | ||
if (reflectionMode === true) { | ||
return '' | ||
} | ||
|
||
const startModule = createStartModuleContent({ | ||
registerTypeScript: { | ||
...layout.tsConfig.content.options, | ||
module: ts.ModuleKind.CommonJS, | ||
target: ts.ScriptTarget.ES2015, | ||
}, | ||
internalStage: 'dev', | ||
runtimePluginManifests: [], // tree-shaking not needed | ||
layout, | ||
absoluteModuleImports: true, | ||
}) | ||
|
||
return transpileModule(startModule, { | ||
...layout.tsConfig.content.options, | ||
module: ts.ModuleKind.CommonJS, | ||
target: ts.ScriptTarget.ES2015, | ||
}) | ||
} |
Uh oh!
There was an error while loading. Please reload this page.