-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
61 additions
and
2 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
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,55 @@ | ||
/** | ||
* Simualated Module Exports | ||
* | ||
* This script builds the modules that will be consumed publically. They front the actual code inside ./dist. | ||
* The problem being solved here is that it allows consumers to do e.g. this: | ||
* | ||
* Import { ... } from 'nexus/testing' | ||
* | ||
* Instead of: | ||
* | ||
* Import { ... } from 'nexus/dist/testing' | ||
* | ||
* This is needed to support Jest: https://github.com/prisma/nexus-prisma/issues/137 | ||
* | ||
* Whatever modules are written here should be: | ||
* | ||
* 1. ignored in .gitignore. <-- YOU MUST DO THIS MANUALLY | ||
* 2. added to the package.json files array <-- Automated for you | ||
*/ | ||
|
||
// TODO automate gitignore step | ||
|
||
import * as fs from 'fs-jetpack' | ||
import * as lo from 'lodash' | ||
import * as os from 'os' | ||
import * as path from 'path' | ||
import { PackageJson } from 'type-fest' | ||
|
||
simulatePackageExports([ | ||
['scalars.d.ts', "export * from './dist-cjs/entrypoints/scalars'"], | ||
['scalars.js', "module.exports = require('./dist-cjs/entrypoints/scalars')"], | ||
['generator.d.ts', "export * from './dist-cjs/entrypoints/generator'"], | ||
['generator.js', "module.exports = require('./dist-cjs/entrypoints/generator')"], | ||
]) | ||
|
||
function simulatePackageExports(facades: ModuleFacade[]) { | ||
// Write facade files | ||
|
||
for (const facade of facades) { | ||
fs.write(facade[0], facade[1] + os.EOL) | ||
} | ||
|
||
// Handle package.json files array | ||
|
||
const packageJsonPath = path.join(__dirname, '..', 'package.json') | ||
const packageJson = fs.read(packageJsonPath, 'json') as PackageJson | ||
|
||
packageJson.files = lo.uniq([...(packageJson.files ?? []), ...facades.map((facade) => facade[0])]) | ||
|
||
const packageJsonString = JSON.stringify(packageJson, null, 2) + os.EOL | ||
|
||
fs.write(packageJsonPath, packageJsonString) | ||
} | ||
|
||
type ModuleFacade = [filePath: string, fileContents: string] |
1705a54
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: