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

version: force proper typing on version literals #3344

Merged
merged 2 commits into from Oct 28, 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
23 changes: 18 additions & 5 deletions resources/build-npm.js
Expand Up @@ -35,16 +35,29 @@ if (require.main === module) {
}
}

const tsProgram = ts.createProgram(['src/index.ts'], {
...ts.getDefaultCompilerOptions(),
// Based on https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#getting-the-dts-from-a-javascript-file
const tsConfig = JSON.parse(
fs.readFileSync(require.resolve('../tsconfig.json'), 'utf-8'),
);
assert(
tsConfig.compilerOptions,
'"tsconfig.json" should have `compilerOptions`',
);
const tsOptions = {
...tsConfig.compilerOptions,
noEmit: false,
declaration: true,
declarationDir: './npmDist',
emitDeclarationOnly: true,
});
};

const tsResult = tsProgram.emit(undefined, (filepath, body) => {
const tsHost = ts.createCompilerHost(tsOptions);
tsHost.writeFile = (filepath, body) => {
writeGeneratedFile(filepath, body);
});
};

const tsProgram = ts.createProgram(['src/index.ts'], tsOptions, tsHost);
const tsResult = tsProgram.emit();
assert(
!tsResult.emitSkipped,
'Fail to generate `*.d.ts` files, please run `npm run check`',
Expand Down
12 changes: 7 additions & 5 deletions resources/gen-version.js
Expand Up @@ -18,16 +18,18 @@ const body = `
/**
* A string containing the version of the GraphQL.js library
*/
export const version = '${version}';
export const version = '${version}' as string;

/**
* An object containing the components of the GraphQL.js version string
*/
export const versionInfo = Object.freeze({
major: ${major},
minor: ${minor},
patch: ${patch},
preReleaseTag: ${preReleaseTag ? `'${preReleaseTag}'` : 'null'},
major: ${major} as number,
minor: ${minor} as number,
patch: ${patch} as number,
preReleaseTag: ${
preReleaseTag ? `'${preReleaseTag}'` : 'null'
} as string | null,
});
`;

Expand Down
10 changes: 5 additions & 5 deletions src/version.ts
Expand Up @@ -4,14 +4,14 @@
/**
* A string containing the version of the GraphQL.js library
*/
export const version = '16.0.0-rc.7';
export const version = '16.0.0-rc.7' as string;

/**
* An object containing the components of the GraphQL.js version string
*/
export const versionInfo = Object.freeze({
major: 16,
minor: 0,
patch: 0,
preReleaseTag: 'rc.7',
major: 16 as number,
minor: 0 as number,
patch: 0 as number,
preReleaseTag: 'rc.7' as string | null,
});