Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions integrationTests/node/index.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import assert from 'node:assert';
import { readFileSync } from 'node:fs';

import { graphqlSync } from 'graphql-esm';
import { astFromValue, buildSchema } from 'graphql-esm/utilities';
import { version } from 'graphql-esm/version';
import { graphqlSync } from 'graphql';
import { astFromValue, buildSchema } from 'graphql/utilities';
import { version } from 'graphql/version';

assert.deepStrictEqual(
version + '+esm',
JSON.parse(readFileSync('./node_modules/graphql-esm/package.json')).version,
version,
JSON.parse(readFileSync('./node_modules/graphql/package.json')).version,
);

const schema = buildSchema('type Query { hello: String }');
Expand Down
3 changes: 1 addition & 2 deletions integrationTests/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"test": "node test.js"
},
"dependencies": {
"graphql": "file:../graphql.tgz",
"graphql-esm": "file:../graphql-esm.tgz"
"graphql": "file:../graphql.tgz"
}
}
10 changes: 3 additions & 7 deletions integrationTests/ts/esm.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import type { ExecutionResult } from 'graphql-esm/execution';
import type { ExecutionResult } from 'graphql/execution';

import { graphqlSync } from 'graphql-esm';
import {
GraphQLString,
GraphQLSchema,
GraphQLObjectType,
} from 'graphql-esm/type';
import { graphqlSync } from 'graphql';
import { GraphQLString, GraphQLSchema, GraphQLObjectType } from 'graphql/type';

const queryType: GraphQLObjectType = new GraphQLObjectType({
name: 'Query',
Expand Down
1 change: 0 additions & 1 deletion integrationTests/ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
},
"dependencies": {
"graphql": "file:../graphql.tgz",
"graphql-esm": "file:../graphql-esm.tgz",
"@types/node": "~24.0.14",
"typescript-4.9": "npm:typescript@4.9.x",
"typescript-5.0": "npm:typescript@5.0.x",
Expand Down
4 changes: 2 additions & 2 deletions integrationTests/webpack/entry-esm.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { graphqlSync } from 'graphql-esm';
import { buildSchema } from 'graphql-esm/utilities/buildASTSchema';
import { graphqlSync } from 'graphql';
import { buildSchema } from 'graphql/utilities/buildASTSchema';

const schema = buildSchema('type Query { hello: String }');

Expand Down
1 change: 0 additions & 1 deletion integrationTests/webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
},
"dependencies": {
"graphql": "file:../graphql.tgz",
"graphql-esm": "file:../graphql-esm.tgz",
"webpack": "5.x.x",
"webpack-cli": "4.x.x"
}
Expand Down
171 changes: 71 additions & 100 deletions resources/build-npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,10 @@ const devTypeFiles = [
] as const;

console.log('\n./npmDist');
await buildPackage('./npmDist', false);
await buildPackage('./npmDist');
showDirStats('./npmDist');

console.log('\n./npmEsmDist');
await buildPackage('./npmEsmDist', true);
showDirStats('./npmEsmDist');

async function buildPackage(outDir: string, isESMOnly: boolean): Promise<void> {
async function buildPackage(outDir: string): Promise<void> {
const devDir = path.join(outDir, '__dev__');

fs.rmSync(outDir, { recursive: true, force: true });
Expand Down Expand Up @@ -79,113 +75,88 @@ async function buildPackage(outDir: string, isESMOnly: boolean): Promise<void> {
'Publish tag and version tag should match!',
);

if (isESMOnly) {
packageJSON.exports = {};

const { emittedTSFiles } = emitTSFiles({ outDir, extension: '.js' });
delete packageJSON.type;
packageJSON.main = 'index.js';
packageJSON.module = 'index.mjs';
packageJSON.types = 'index.d.ts';

for (const filepath of emittedTSFiles) {
if (path.basename(filepath) === 'index.js') {
const relativePath = './' + path.relative('./npmEsmDist', filepath);
packageJSON.exports[path.dirname(relativePath)] = relativePath;
}
const { emittedTSFiles } = emitTSFiles({
outDir,
module: 'commonjs',
moduleResolution: 'node10',
extension: '.js',
});
emitTSFiles({ outDir, extension: '.mjs' });

packageJSON.exports = {};
for (const prodFile of emittedTSFiles) {
const { dir, base, name, ext } = path.parse(prodFile);

if (ext === '.map') {
continue;
} else if (path.basename(dir) === 'dev') {
packageJSON.exports['./dev'] = buildPlatformConditionalExports(
'./dev',
'index',
);
continue;
}

packageJSON.exports['./*.js'] = './*.js';
packageJSON.exports['./*'] = './*.js';

packageJSON.publishConfig.tag += '-esm';
packageJSON.version += '+esm';
} else {
delete packageJSON.type;
packageJSON.main = 'index.js';
packageJSON.module = 'index.mjs';
packageJSON.types = 'index.d.ts';

const { emittedTSFiles } = emitTSFiles({
outDir,
module: 'commonjs',
moduleResolution: 'node10',
extension: '.js',
});
emitTSFiles({ outDir, extension: '.mjs' });

packageJSON.exports = {};
for (const prodFile of emittedTSFiles) {
const { dir, base, name, ext } = path.parse(prodFile);

if (ext === '.map') {
continue;
} else if (path.basename(dir) === 'dev') {
packageJSON.exports['./dev'] = buildPlatformConditionalExports(
'./dev',
'index',
);
continue;
}
const relativePathToProd = path.relative(prodFile, outDir);

const relativePathToProd = path.relative(prodFile, outDir);
const { name: innerName, ext: innerExt } = path.parse(name);

const { name: innerName, ext: innerExt } = path.parse(name);
if (innerExt === '.d') {
const relativePathAndName = path.relative(outDir, `${dir}/${innerName}`);

if (innerExt === '.d') {
const relativePathAndName = path.relative(
outDir,
`${dir}/${innerName}`,
for (const [typeExt, targetExt] of devTypeFiles) {
const line = `export * from '${relativePathToProd}/${relativePathAndName}${targetExt}';`;
writeGeneratedFile(
path.join(devDir, path.relative(outDir, `${dir}/${name}${typeExt}`)),
line,
);

for (const [typeExt, targetExt] of devTypeFiles) {
const line = `export * from '${relativePathToProd}/${relativePathAndName}${targetExt}';`;
writeGeneratedFile(
path.join(
devDir,
path.relative(outDir, `${dir}/${name}${typeExt}`),
),
line,
);
}
continue;
}
continue;
}

const relativePathAndName = path.relative(outDir, `${dir}/${name}`);

writeGeneratedFile(
path.join(devDir, path.relative(outDir, `${dir}/${name}.js`)),
buildCJSDevModeStub(
`${relativePathToProd}/devMode.js`,
`${relativePathToProd}/${relativePathAndName}.js`,
),
);

writeGeneratedFile(
path.join(devDir, path.relative(outDir, `${dir}/${name}.mjs`)),
buildESMDevModeStub(
`${relativePathToProd}/devMode.mjs`,
`${relativePathToProd}/${relativePathAndName}.mjs`,
const relativePathAndName = path.relative(outDir, `${dir}/${name}`);

writeGeneratedFile(
path.join(devDir, path.relative(outDir, `${dir}/${name}.js`)),
buildCJSDevModeStub(
`${relativePathToProd}/devMode.js`,
`${relativePathToProd}/${relativePathAndName}.js`,
),
);

writeGeneratedFile(
path.join(devDir, path.relative(outDir, `${dir}/${name}.mjs`)),
buildESMDevModeStub(
`${relativePathToProd}/devMode.mjs`,
`${relativePathToProd}/${relativePathAndName}.mjs`,
),
);

if (base === 'index.js') {
const dirname = path.dirname(relativePathAndName);
packageJSON.exports[dirname === '.' ? dirname : `./${dirname}`] = {
development: buildPlatformConditionalExports(
'./__dev__',
relativePathAndName,
),
);

if (base === 'index.js') {
const dirname = path.dirname(relativePathAndName);
packageJSON.exports[dirname === '.' ? dirname : `./${dirname}`] = {
development: buildPlatformConditionalExports(
'./__dev__',
relativePathAndName,
),
default: buildPlatformConditionalExports('.', relativePathAndName),
};
}
default: buildPlatformConditionalExports('.', relativePathAndName),
};
}
}

const globEntryPoints = {
development: buildPlatformConditionalExports('./__dev__', '*'),
default: buildPlatformConditionalExports('.', '*'),
};
packageJSON.exports['./*.js'] = globEntryPoints;
packageJSON.exports['./*'] = globEntryPoints;
const globEntryPoints = {
development: buildPlatformConditionalExports('./__dev__', '*'),
default: buildPlatformConditionalExports('.', '*'),
};
packageJSON.exports['./*.js'] = globEntryPoints;
packageJSON.exports['./*'] = globEntryPoints;

packageJSON.sideEffects = ['__dev__/*'];
}
packageJSON.sideEffects = ['__dev__/*'];

const packageJsonPath = `./${outDir}/package.json`;
const prettified = await prettify(
Expand Down
6 changes: 0 additions & 6 deletions resources/integration-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ describe('Integration Tests', () => {
const archiveName = npm({ cwd: tmpDirPath(), quiet: true }).pack(distDir);
fs.renameSync(tmpDirPath(archiveName), tmpDirPath('graphql.tgz'));

const esmDistDir = localRepoPath('npmEsmDist');
const archiveEsmName = npm({ cwd: tmpDirPath(), quiet: true }).pack(
esmDistDir,
);
fs.renameSync(tmpDirPath(archiveEsmName), tmpDirPath('graphql-esm.tgz'));

npm().run('build:deno');
fs.cpSync(localRepoPath('denoDist'), tmpDirPath('graphql-deno-dist'), {
recursive: true,
Expand Down
Loading