fix: fix package.json exports TypeScript resolution (#17181)

This commit is contained in:
Alyx 2024-03-19 17:38:18 +01:00 committed by GitHub
parent 2d15ccb444
commit 23a0cb4544
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 67 additions and 112 deletions

View File

@ -35,7 +35,7 @@ jobs:
- name: Reset NX cache
run: yarn nx reset
- name: Compress artifact
run: tar -cf install-build-node-${{ matrix.node-version }}.tar ./packages/core/lib ./packages/core/types ./packages/validator-js/lib ./packages/validator-js/types ./packages/utils/lib ./node_modules
run: tar -cf install-build-node-${{ matrix.node-version }}.tar ./packages/core/lib ./packages/validator-js/lib ./packages/utils/lib ./node_modules
- uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: install-build-artifact-node-${{ matrix.node-version }}

View File

@ -1,2 +1,3 @@
yarn lint-staged --concurrent false
yarn delete-changelog
git add .

View File

@ -1,19 +0,0 @@
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [7.0.0-alpha.38](https://github.com/sequelize/sequelize/compare/v7.0.0-alpha.37...v7.0.0-alpha.38) (2024-03-19)
### Bug Fixes
- **mysql:** use public TypeCastField type ([#17136](https://github.com/sequelize/sequelize/issues/17136)) ([7ab30dc](https://github.com/sequelize/sequelize/commit/7ab30dc2da21386c56d4944a6a10205dad735c10))
- reduce internal usages of deprecated APIs ([#17112](https://github.com/sequelize/sequelize/issues/17112)) ([f1db523](https://github.com/sequelize/sequelize/commit/f1db523c7779c7754af3d8af60e57e67b743e562))
- remove TableNameOrModel ([#17080](https://github.com/sequelize/sequelize/issues/17080)) ([dfc90b8](https://github.com/sequelize/sequelize/commit/dfc90b8ee622539277a95da9d34b933f06a4eb43))
### Features
- add `@sequelize/utils` package ([#17168](https://github.com/sequelize/sequelize/issues/17168)) ([1d96a59](https://github.com/sequelize/sequelize/commit/1d96a59b2397f1f7e4b196ea281674d71a697e58))
- implement `Model._UNSTABLE_destroyMany` ([#17031](https://github.com/sequelize/sequelize/issues/17031)) ([1fead8a](https://github.com/sequelize/sequelize/commit/1fead8a34538a71a677340be28f07c3a49f3a7d6))
- migrate transactions to typescript ([#16903](https://github.com/sequelize/sequelize/issues/16903)) ([ed47bcb](https://github.com/sequelize/sequelize/commit/ed47bcba8a1dae605d572926d46ee0a75eec4f1b))
- **postgres:** add MACADDR8 DataType ([#17059](https://github.com/sequelize/sequelize/issues/17059)) ([c64b3c2](https://github.com/sequelize/sequelize/commit/c64b3c2e775dd2b30addee36c1484e385ff01a9c))

View File

@ -30,7 +30,6 @@ console.info(`Compiling package ${packageName}`);
const packageDir = `${rootDir}/packages/${packageName}`;
const sourceDir = path.join(packageDir, 'src');
const libDir = path.join(packageDir, 'lib');
const typesDir = path.join(packageDir, 'types');
const [sourceFiles] = await Promise.all([
// Find all .js and .ts files from /src.
@ -40,33 +39,22 @@ const [sourceFiles] = await Promise.all([
}),
// Delete /lib for a full rebuild.
rmDir(libDir),
// Delete /types for a full rebuild.
rmDir(typesDir),
]);
const filesToCompile = [];
const filesToCopyToLib = [];
const declarationFiles = [];
for (const file of sourceFiles) {
// mjs files cannot be built as they would be compiled to commonjs
if (file.endsWith('.mjs')) {
if (file.endsWith('.mjs') || file.endsWith('.d.ts')) {
filesToCopyToLib.push(file);
} else if (file.endsWith('.d.ts')) {
declarationFiles.push(file);
} else {
filesToCompile.push(file);
}
}
// copy .d.ts files prior to generating them from the .ts files
// so the .ts files in lib/ will take priority..
await Promise.all([
copyFiles(declarationFiles, sourceDir, typesDir),
copyFiles(filesToCopyToLib, sourceDir, libDir),
]);
await Promise.all([
build({
// Adds source mapping
sourcemap: true,
@ -89,6 +77,18 @@ await Promise.all([
}),
]);
const indexFiles = await glob(`${glob.convertPathToPattern(libDir)}/**/index.d.ts`, {
onlyFiles: true,
absolute: false,
});
// copy .d.ts files to .d.mts to provide typings for the ESM entrypoint
await Promise.all(
indexFiles.map(async indexFile => {
await fs.copyFile(indexFile, indexFile.replace(/.d.ts$/, '.d.mts'));
}),
);
async function rmDir(dirName) {
try {
await fs.stat(dirName);

View File

@ -1,19 +0,0 @@
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [7.0.0-alpha.38](https://github.com/sequelize/sequelize/compare/v7.0.0-alpha.37...v7.0.0-alpha.38) (2024-03-19)
### Bug Fixes
- **mysql:** use public TypeCastField type ([#17136](https://github.com/sequelize/sequelize/issues/17136)) ([7ab30dc](https://github.com/sequelize/sequelize/commit/7ab30dc2da21386c56d4944a6a10205dad735c10))
- reduce internal usages of deprecated APIs ([#17112](https://github.com/sequelize/sequelize/issues/17112)) ([f1db523](https://github.com/sequelize/sequelize/commit/f1db523c7779c7754af3d8af60e57e67b743e562))
- remove TableNameOrModel ([#17080](https://github.com/sequelize/sequelize/issues/17080)) ([dfc90b8](https://github.com/sequelize/sequelize/commit/dfc90b8ee622539277a95da9d34b933f06a4eb43))
### Features
- add `@sequelize/utils` package ([#17168](https://github.com/sequelize/sequelize/issues/17168)) ([1d96a59](https://github.com/sequelize/sequelize/commit/1d96a59b2397f1f7e4b196ea281674d71a697e58))
- implement `Model._UNSTABLE_destroyMany` ([#17031](https://github.com/sequelize/sequelize/issues/17031)) ([1fead8a](https://github.com/sequelize/sequelize/commit/1fead8a34538a71a677340be28f07c3a49f3a7d6))
- migrate transactions to typescript ([#16903](https://github.com/sequelize/sequelize/issues/16903)) ([ed47bcb](https://github.com/sequelize/sequelize/commit/ed47bcba8a1dae605d572926d46ee0a75eec4f1b))
- **postgres:** add MACADDR8 DataType ([#17059](https://github.com/sequelize/sequelize/issues/17059)) ([c64b3c2](https://github.com/sequelize/sequelize/commit/c64b3c2e775dd2b30addee36c1484e385ff01a9c))

View File

@ -17,21 +17,27 @@
},
"homepage": "https://sequelize.org/",
"main": "./lib/index.js",
"types": "./types/index.d.ts",
"types": "./lib/index.d.ts",
"type": "commonjs",
"exports": {
".": {
"types": "./types/index.d.ts",
"import": "./lib/index.mjs",
"require": "./lib/index.js"
"import": {
"types": "./lib/index.d.mts",
"default": "./lib/index.mjs"
},
"require": {
"types": "./lib/index.d.ts",
"default": "./lib/index.js"
}
},
"./decorators-legacy": {
"types": "./types/decorators/legacy/index.d.ts",
"import": "./lib/decorators/legacy/index.mjs",
"require": "./lib/decorators/legacy/index.js"
"require": {
"types": "./lib/decorators/legacy/index.d.ts",
"default": "./lib/decorators/legacy/index.js"
}
},
"./_non-semver-use-at-your-own-risk_/*": {
"types": "./types/*",
"default": "./lib/*"
},
"./package.json": "./package.json"

View File

@ -1,4 +1,4 @@
import { isNodeError } from '@sequelize/utils/node.js';
import { isNodeError } from '@sequelize/utils/node';
import cloneDeep from 'lodash/cloneDeep';
import semver from 'semver';
import { TimeoutError } from 'sequelize-pool';

View File

@ -1,5 +1,5 @@
import { isError } from '@sequelize/utils';
import { isNodeError } from '@sequelize/utils/node.js';
import { isNodeError } from '@sequelize/utils/node';
import dayjs from 'dayjs';
import type {
Connection,

View File

@ -1,5 +1,5 @@
import { map } from '@sequelize/utils';
import { checkFileExists } from '@sequelize/utils/node.js';
import { checkFileExists } from '@sequelize/utils/node';
import fs from 'node:fs/promises';
import path from 'node:path';
import { promisify } from 'node:util';

View File

@ -11,7 +11,7 @@
* @module
*/
export * as DataTypes from './data-types';
export * as DataTypes from './data-types.js';
export type {
ArrayOptions,
BindParamOptions,
@ -43,10 +43,10 @@ export type {
GeoJsonPolygon,
PositionPosition,
} from './geo-json.js';
export { IndexHints } from './index-hints';
export { Op, type OpTypes } from './operators';
export { QueryTypes } from './query-types';
export { TableHints } from './table-hints';
export { IndexHints } from './index-hints.js';
export { Op, type OpTypes } from './operators.js';
export { QueryTypes } from './query-types.js';
export { TableHints } from './table-hints.js';
export {
IsolationLevel,
Lock,
@ -56,18 +56,18 @@ export {
type ManagedTransactionOptions,
type NormalizedTransactionOptions,
type TransactionOptions,
} from './transaction';
} from './transaction.js';
export * from './associations/index';
export type { Connection } from './dialects/abstract/connection-manager';
export * from './dialects/abstract/query-generator.types';
export * from './dialects/abstract/query-interface';
export * from './dialects/abstract/query-interface.types';
export * from './errors';
export * from './model';
export * from './sequelize';
export * from './associations/index.js';
export type { Connection } from './dialects/abstract/connection-manager.js';
export * from './dialects/abstract/query-generator.types.js';
export * from './dialects/abstract/query-interface.js';
export * from './dialects/abstract/query-interface.types.js';
export * from './errors/index.js';
export * from './model.js';
export * from './sequelize.js';
export { ConstraintChecking, Deferrable } from './deferrable';
export { ConstraintChecking, Deferrable } from './deferrable.js';
export { AbstractDialect } from './dialects/abstract/index.js';
export { AbstractQueryGenerator } from './dialects/abstract/query-generator.js';
export type { WhereOptions } from './dialects/abstract/where-sql-builder-types.js';
@ -76,10 +76,10 @@ export { ModelDefinition } from './model-definition.js';
// TODO [>=8]: remove this alias
// eslint-disable-next-line import/no-default-export -- legacy, will be removed in the future
export { Sequelize as default } from './sequelize';
export { isModelStatic, isSameInitialModel } from './utils/model-utils';
export { useInflection } from './utils/string';
export type { Validator } from './utils/validator-extras';
export { Sequelize as default } from './sequelize.js';
export { isModelStatic, isSameInitialModel } from './utils/model-utils.js';
export { useInflection } from './utils/string.js';
export type { Validator } from './utils/validator-extras.js';
export { AssociationPath } from './expression-builders/association-path.js';
export { Attribute } from './expression-builders/attribute.js';

View File

@ -1,6 +1,6 @@
import type { Dialect, Options } from '@sequelize/core';
import { Sequelize } from '@sequelize/core';
import { isNodeError } from '@sequelize/utils/node.js';
import { isNodeError } from '@sequelize/utils/node';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import chaiDatetime from 'chai-datetime';

View File

@ -6,7 +6,7 @@
"allowJs": false,
"declaration": true,
"sourceRoot": "",
"outDir": "./types",
"outDir": "./lib",
"strict": true,
"baseUrl": "./",
"rootDir": "./src",

View File

@ -1,10 +0,0 @@
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [7.0.0-alpha.38](https://github.com/sequelize/sequelize/compare/v7.0.0-alpha.37...v7.0.0-alpha.38) (2024-03-19)
### Features
- add `@sequelize/utils` package ([#17168](https://github.com/sequelize/sequelize/issues/17168)) ([1d96a59](https://github.com/sequelize/sequelize/commit/1d96a59b2397f1f7e4b196ea281674d71a697e58))

View File

@ -4,13 +4,14 @@
"engines": {
"node": ">=18.0.0"
},
"types": "./lib/common/index.d.ts",
"exports": {
".": {
"node": "./lib/common/index.node.js",
"default": "./lib/common/index.js",
"types": "./lib/common/index.d.ts"
"types": "./lib/common/index.d.ts",
"default": "./lib/common/index.js"
},
"./node.js": {
"./node": {
"node": "./lib/node/index.js",
"types": "./lib/node/index.d.ts"
}
@ -22,7 +23,7 @@
"repository": "https://github.com/sequelize/sequelize",
"scripts": {
"test": "concurrently \"npm:test-*\"",
"build": "tsc --project tsconfig.build.json",
"build": "../../build-packages.mjs utils",
"test-typings": "tsc --noEmit --project tsconfig.json",
"test-unit": "mocha src/**/*.test.ts -r ../../test/register-esbuild.js",
"test-exports": "../../dev/sync-exports.mjs ./src --check-outdated",

View File

@ -1,10 +0,0 @@
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [7.0.0-alpha.38](https://github.com/sequelize/sequelize/compare/v7.0.0-alpha.37...v7.0.0-alpha.38) (2024-03-19)
### Features
- add `@sequelize/utils` package ([#17168](https://github.com/sequelize/sequelize/issues/17168)) ([1d96a59](https://github.com/sequelize/sequelize/commit/1d96a59b2397f1f7e4b196ea281674d71a697e58))

View File

@ -22,12 +22,17 @@
"build": "../../build-packages.mjs validator-js"
},
"main": "./lib/index.js",
"types": "./types/index.d.ts",
"types": "./lib/index.d.ts",
"exports": {
".": {
"types": "./types/index.d.ts",
"import": "./lib/index.mjs",
"require": "./lib/index.js"
"import": {
"types": "./lib/index.d.mts",
"default": "./lib/index.mjs"
},
"require": {
"types": "./lib/index.d.ts",
"default": "./lib/index.js"
}
},
"./package.json": "./package.json"
},

View File

@ -6,7 +6,7 @@
"allowJs": false,
"declaration": true,
"sourceRoot": "",
"outDir": "./types",
"outDir": "./lib",
"strict": true,
"baseUrl": "./",
"rootDir": "./src",