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

feat: gen /lib & /types from /src & drop /dist (v6) #14063

Merged
merged 7 commits into from
Feb 8, 2022
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
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
"ecmaVersion": 2020,
"sourceType": "script"
},
"ignorePatterns": ["dist/**/*", "types/**/*"],
"ignorePatterns": ["lib/**/*", "types/**/*", "test/types/**/*", "src/**/*.d.ts"],
"plugins": ["mocha", "jsdoc", "@typescript-eslint"],
"env": {
"node": true,
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ test/binary/tmp/*
.vscode/
esdoc
node_modules
dist
/lib
WikiRik marked this conversation as resolved.
Show resolved Hide resolved
/types
56 changes: 38 additions & 18 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,23 @@ const copyFile = promisify(fs.copyFile);

// if this script is moved, this will need to be adjusted
const rootDir = __dirname;
const outdir = path.join(rootDir, 'dist');
const outdir = path.join(rootDir, 'lib');
const typesDir = path.join(rootDir, 'types');

const nodeMajorVersion = Number(process.version.match(/(?<=^v)\d+/));

async function rmDistDir() {
async function rmDir(dirName) {
try {
await stat(outdir);
await stat(dirName);
if (nodeMajorVersion >= 14) {
const rm = promisify(fs.rm);
await rm(outdir, { recursive: true });
await rm(dirName, { recursive: true });
} else {
const rmdir = promisify(fs.rmdir);
if (nodeMajorVersion >= 12) {
await rmdir(outdir, { recursive: true });
await rmdir(dirName, { recursive: true });
} else {
await rmdir(outdir);
await rmdir(dirName);
}}
} catch {
/* no-op */
Expand All @@ -37,23 +38,46 @@ async function rmDistDir() {

async function main() {
console.log('Compiling sequelize...');
const [declarationFiles, filesToCompile] = await Promise.all([
// Find all .d.ts files from types/
glob('./types/**/*.d.ts', { onlyFiles: true, absolute: false }),
// Find all .js and .ts files from lib/
glob('./lib/**/*.[tj]s', { onlyFiles: true, absolute: false }),
// Delete dist/ for a full rebuild.
rmDistDir()
const [sourceFiles] = await Promise.all([
// Find all .js and .ts files from /src
glob('./src/**/*.{mjs,cjs,js,mts,cts,ts}', { onlyFiles: true, absolute: false }),
// Delete /lib for a full rebuild.
rmDir(outdir),
// 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')) {
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 copyFiles(
// The last path in the list is the output directory
declarationFiles.concat(outdir),
declarationFiles.concat(typesDir),
{ up: 1 }
);

if (filesToCopyToLib.length > 0) {
await copyFiles(
// The last path in the list is the output directory
filesToCopyToLib.concat(outdir),
{ up: 1 }
);
}

await Promise.all([
build({
// Adds source mapping
Expand All @@ -65,13 +89,9 @@ async function main() {

outdir,
entryPoints: filesToCompile
.concat('./index.js')
.map(file => path.resolve(file))
}),

// not passed to "build" because we need this file to stay as ESM instead of CJS
copyFile('./index.mjs', path.resolve(outdir, './index.mjs')),

exec('tsc', {
env: {
// binaries installed from modules have symlinks in
Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
'use strict';

// TODO [>=7]: remove me. I've been moved to 'exports' in package.json

/**
* A Sequelize module that contains the sequelize entry point.
*
* @module sequelize
*/

/** Exports the sequelize entry point. */
module.exports = require('./lib/sequelize');
module.exports = require('./lib');
23 changes: 10 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,25 @@
"url": "https://github.com/sequelize/sequelize/issues"
},
"homepage": "https://sequelize.org/",
"main": "./dist/index.js",
"types": "./dist",
"main": "./lib/index.js",
"types": "./types",
"type": "commonjs",
"exports": {
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.js"
"import": "./lib/index.mjs",
"require": "./lib/index.js"
},
"./lib/*": "./dist/lib/*.js",
"./lib/errors": "./dist/lib/errors/index.js",
"./lib/*": "./lib/*.js",
"./lib/errors": "./lib/errors/index.js",
"./*": "./*"
},
"engines": {
"node": ">=10.0.0"
},
"files": [
"dist",
"lib",
"index.js",
"types/index.d.ts",
"types/lib",
"types/type-helpers"
"types",
"index.js"
],
"license": "MIT",
"dependencies": {
Expand Down Expand Up @@ -211,9 +208,9 @@
},
"scripts": {
"----------------------------------------- static analysis -----------------------------------------": "",
"lint": "eslint lib test --quiet --fix",
"lint": "eslint src test --quiet --fix",
"lint-docs": "markdownlint docs",
"test-typings": "tsc -b types/tsconfig.json && tsc -b types/test/tsconfig.json && tsc --noEmit --emitDeclarationOnly false && tsc -b test/tsconfig.json",
"test-typings": "tsc --noEmit --emitDeclarationOnly false && tsc -b test/tsconfig.json",
"----------------------------------------- documentation -------------------------------------------": "",
"docs": "rimraf esdoc && esdoc -c docs/esdoc-config.js && cp docs/favicon.ico esdoc/favicon.ico && cp docs/ROUTER.txt esdoc/ROUTER && node docs/run-docs-transforms.js && node docs/redirects/create-redirects.js && rimraf esdoc/file esdoc/source.html",
"----------------------------------------- tests ---------------------------------------------------": "",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DataType } from './data-types';
import { DataType } from '../../data-types';
import {
Logging,
Model,
Expand All @@ -12,14 +12,14 @@ import {
ModelStatic,
ModelType,
CreationAttributes,
Attributes,
} from './model';
import QueryTypes = require('./query-types');
import { Sequelize, RetryOptions } from './sequelize';
import { Transaction } from './transaction';
import { SetRequired } from './../type-helpers/set-required';
import { Fn, Literal } from './utils';
import { Deferrable } from './deferrable';
Attributes
} from '../../model';
import QueryTypes = require('../../query-types');
import { Sequelize, RetryOptions } from '../../sequelize';
import { Transaction } from '../../transaction';
import { SetRequired } from '../../utils/set-required';
import { Fn, Literal } from '../../utils';
import { Deferrable } from '../../deferrable';

type BindOrReplacements = { [key: string]: unknown } | unknown[];
type FieldMap = { [key: string]: string };
Expand Down
24 changes: 18 additions & 6 deletions types/lib/query.d.ts → src/dialects/abstract/query.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { IncludeOptions } from '..';
import { Connection } from './connection-manager';
import {
Model, ModelType
} from './model';
import { Sequelize } from './sequelize';
import QueryTypes = require('./query-types');
import { Model, ModelType, IncludeOptions } from '../../model';
import { Sequelize } from '../../sequelize';
import QueryTypes = require('../../query-types');

type BindOrReplacements = { [key: string]: unknown } | unknown[];
type FieldMap = { [key: string]: string };
Expand Down Expand Up @@ -161,24 +158,28 @@ export class AbstractQuery {

/**
* Checks if the query type is RAW
*
* @returns {boolean}
*/
public isRawQuery(): boolean;

/**
* Checks if the query type is VERSION
*
* @returns {boolean}
*/
public isVersionQuery(): boolean;

/**
* Checks if the query type is UPSERT
*
* @returns {boolean}
*/
public isUpsertQuery(): boolean;

/**
* Checks if the query type is INSERT
*
* @returns {boolean}
*/
public isInsertQuery(results?: unknown[], metaData?: unknown): boolean;
Expand All @@ -194,6 +195,7 @@ export class AbstractQuery {

/**
* Checks if the query type is SHOWTABLES
*
* @returns {boolean}
*/
public isShowTablesQuery(): boolean;
Expand All @@ -208,48 +210,56 @@ export class AbstractQuery {

/**
* Checks if the query type is SHOWINDEXES
*
* @returns {boolean}
*/
public isShowIndexesQuery(): boolean;

/**
* Checks if the query type is SHOWCONSTRAINTS
*
* @returns {boolean}
*/
public isShowConstraintsQuery(): boolean;

/**
* Checks if the query type is DESCRIBE
*
* @returns {boolean}
*/
public isDescribeQuery(): boolean;

/**
* Checks if the query type is SELECT
*
* @returns {boolean}
*/
public isSelectQuery(): boolean;

/**
* Checks if the query type is BULKUPDATE
*
* @returns {boolean}
*/
public isBulkUpdateQuery(): boolean;

/**
* Checks if the query type is BULKDELETE
*
* @returns {boolean}
*/
public isBulkDeleteQuery(): boolean;

/**
* Checks if the query type is FOREIGNKEYS
*
* @returns {boolean}
*/
public isForeignKeysQuery(): boolean;

/**
* Checks if the query type is UPDATE
*
* @returns {boolean}
*/
public isUpdateQuery(): boolean;
Expand All @@ -264,12 +274,14 @@ export class AbstractQuery {

/**
* Checks if the query starts with 'show' or 'describe'
*
* @returns {boolean}
*/
public isShowOrDescribeQuery(): boolean;

/**
* Checks if the query starts with 'call'
*
* @returns {boolean}
*/
public isCallQuery(): boolean;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Model } from '../..';
import type { Model } from '..';
import BaseError from './base-error';

/**
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ConnectionError from './../connection-error';
import ConnectionError from '../connection-error';

/**
* Thrown when a connection to a database is refused due to insufficient privileges
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Model } from '../..';
import type { Model } from '..';
import type { ErrorOptions } from './base-error';
import BaseError from './base-error';

Expand Down
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions types/lib/hooks.d.ts → src/hooks.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Attributes, CreationAttributes, ModelType } from '../index';
import { ValidationOptions } from './instance-validator';
import Model, {
BulkCreateOptions,
Expand All @@ -9,10 +8,11 @@ import Model, {
InstanceRestoreOptions,
InstanceUpdateOptions,
ModelAttributes,
ModelOptions, RestoreOptions, UpdateOptions, UpsertOptions
ModelOptions, RestoreOptions, UpdateOptions, UpsertOptions,
Attributes, CreationAttributes, ModelType
} from './model';
import { AbstractQuery } from './query';
import { QueryOptions } from './query-interface';
import { AbstractQuery } from './dialects/abstract/query';
import { QueryOptions } from './dialects/abstract/query-interface';
import { Config, Options, Sequelize, SyncOptions } from './sequelize';
import { DeepWriteable } from './utils';

Expand All @@ -34,7 +34,7 @@ export interface ModelHooks<M extends Model = Model, TAttributes = any> {
beforeUpdate(instance: M, options: InstanceUpdateOptions<TAttributes>): HookReturn;
afterUpdate(instance: M, options: InstanceUpdateOptions<TAttributes>): HookReturn;
beforeUpsert(attributes: M, options: UpsertOptions<TAttributes>): HookReturn;
afterUpsert(attributes: [ M, boolean | null ], options: UpsertOptions<TAttributes>): HookReturn;
afterUpsert(attributes: [ M, boolean | null ], options: UpsertOptions<TAttributes>): HookReturn;
beforeSave(
instance: M,
options: InstanceUpdateOptions<TAttributes> | CreateOptions<TAttributes>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.