add login/sign-up page with dark/light mode
This commit is contained in:
+201
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
+398
@@ -0,0 +1,398 @@
|
||||
/**
|
||||
* An interface that exposes some basic information about the
|
||||
* adapter like its name and provider type.
|
||||
*/
|
||||
declare interface AdapterInfo {
|
||||
readonly provider: Provider;
|
||||
readonly adapterName: (typeof officialPrismaAdapters)[number] | (string & {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Original `quaint::ValueType` enum tag from Prisma's `quaint`.
|
||||
* Query arguments marked with this type are sanitized before being sent to the database.
|
||||
* Notice while a query argument may be `null`, `ArgType` is guaranteed to be defined.
|
||||
*/
|
||||
declare type ArgType = 'Int32' | 'Int64' | 'Float' | 'Double' | 'Text' | 'Enum' | 'EnumArray' | 'Bytes' | 'Boolean' | 'Char' | 'Array' | 'Numeric' | 'Json' | 'Xml' | 'Uuid' | 'DateTime' | 'Date' | 'Time' | 'Unknown';
|
||||
|
||||
declare type ColumnType = (typeof ColumnTypeEnum)[keyof typeof ColumnTypeEnum];
|
||||
|
||||
declare const ColumnTypeEnum: {
|
||||
readonly Int32: 0;
|
||||
readonly Int64: 1;
|
||||
readonly Float: 2;
|
||||
readonly Double: 3;
|
||||
readonly Numeric: 4;
|
||||
readonly Boolean: 5;
|
||||
readonly Character: 6;
|
||||
readonly Text: 7;
|
||||
readonly Date: 8;
|
||||
readonly Time: 9;
|
||||
readonly DateTime: 10;
|
||||
readonly Json: 11;
|
||||
readonly Enum: 12;
|
||||
readonly Bytes: 13;
|
||||
readonly Set: 14;
|
||||
readonly Uuid: 15;
|
||||
readonly Int32Array: 64;
|
||||
readonly Int64Array: 65;
|
||||
readonly FloatArray: 66;
|
||||
readonly DoubleArray: 67;
|
||||
readonly NumericArray: 68;
|
||||
readonly BooleanArray: 69;
|
||||
readonly CharacterArray: 70;
|
||||
readonly TextArray: 71;
|
||||
readonly DateArray: 72;
|
||||
readonly TimeArray: 73;
|
||||
readonly DateTimeArray: 74;
|
||||
readonly JsonArray: 75;
|
||||
readonly EnumArray: 76;
|
||||
readonly BytesArray: 77;
|
||||
readonly UuidArray: 78;
|
||||
readonly UnknownNumber: 128;
|
||||
};
|
||||
|
||||
export declare type ConfigFromFile = {
|
||||
resolvedPath: string;
|
||||
config: PrismaConfigInternal<any>;
|
||||
error?: never;
|
||||
} | {
|
||||
resolvedPath: string;
|
||||
config?: never;
|
||||
error: LoadConfigFromFileError;
|
||||
} | {
|
||||
resolvedPath: null;
|
||||
config: PrismaConfigInternal<any>;
|
||||
error?: never;
|
||||
};
|
||||
|
||||
declare type ConnectionInfo = {
|
||||
schemaName?: string;
|
||||
maxBindValues?: number;
|
||||
};
|
||||
|
||||
/**
|
||||
* This default config can be used as basis for unit and integration tests.
|
||||
*/
|
||||
export declare function defaultTestConfig<Env extends Record<string, string | undefined> = never>(): PrismaConfigInternal<Env>;
|
||||
|
||||
/**
|
||||
* Define the configuration for the Prisma Development Kit.
|
||||
*/
|
||||
export declare function defineConfig<Env extends Record<string, string | undefined> = never>(configInput: PrismaConfig<Env>): PrismaConfigInternal<Env>;
|
||||
|
||||
/**
|
||||
* A generic driver adapter factory that allows the user to instantiate a
|
||||
* driver adapter. The query and result types are specific to the adapter.
|
||||
*/
|
||||
declare interface DriverAdapterFactory<Query, Result> extends AdapterInfo {
|
||||
/**
|
||||
* Instantiate a driver adapter.
|
||||
*/
|
||||
connect(): Promise<Queryable<Query, Result>>;
|
||||
}
|
||||
|
||||
declare type EnvVars = Record<string, string | undefined>;
|
||||
|
||||
declare type Error_2 = {
|
||||
kind: 'GenericJs';
|
||||
id: number;
|
||||
} | {
|
||||
kind: 'UnsupportedNativeDataType';
|
||||
type: string;
|
||||
} | {
|
||||
kind: 'InvalidIsolationLevel';
|
||||
level: string;
|
||||
} | {
|
||||
kind: 'LengthMismatch';
|
||||
column?: string;
|
||||
} | {
|
||||
kind: 'UniqueConstraintViolation';
|
||||
fields: string[];
|
||||
} | {
|
||||
kind: 'NullConstraintViolation';
|
||||
fields: string[];
|
||||
} | {
|
||||
kind: 'ForeignKeyConstraintViolation';
|
||||
constraint?: {
|
||||
fields: string[];
|
||||
} | {
|
||||
index: string;
|
||||
} | {
|
||||
foreignKey: {};
|
||||
};
|
||||
} | {
|
||||
kind: 'DatabaseDoesNotExist';
|
||||
db?: string;
|
||||
} | {
|
||||
kind: 'DatabaseAlreadyExists';
|
||||
db?: string;
|
||||
} | {
|
||||
kind: 'DatabaseAccessDenied';
|
||||
db?: string;
|
||||
} | {
|
||||
kind: 'AuthenticationFailed';
|
||||
user?: string;
|
||||
} | {
|
||||
kind: 'TransactionWriteConflict';
|
||||
} | {
|
||||
kind: 'TableDoesNotExist';
|
||||
table?: string;
|
||||
} | {
|
||||
kind: 'ColumnNotFound';
|
||||
column?: string;
|
||||
} | {
|
||||
kind: 'TooManyConnections';
|
||||
cause: string;
|
||||
} | {
|
||||
kind: 'SocketTimeout';
|
||||
} | {
|
||||
kind: 'postgres';
|
||||
code: string;
|
||||
severity: string;
|
||||
message: string;
|
||||
detail: string | undefined;
|
||||
column: string | undefined;
|
||||
hint: string | undefined;
|
||||
} | {
|
||||
kind: 'mysql';
|
||||
code: number;
|
||||
message: string;
|
||||
state: string;
|
||||
} | {
|
||||
kind: 'sqlite';
|
||||
/**
|
||||
* Sqlite extended error code: https://www.sqlite.org/rescode.html
|
||||
*/
|
||||
extendedCode: number;
|
||||
message: string;
|
||||
};
|
||||
|
||||
declare type ErrorCapturingFunction<T> = T extends (...args: infer A) => Promise<infer R> ? (...args: A) => Promise<Result<ErrorCapturingInterface<R>>> : T extends (...args: infer A) => infer R ? (...args: A) => Result<ErrorCapturingInterface<R>> : T;
|
||||
|
||||
declare type ErrorCapturingInterface<T> = {
|
||||
[K in keyof T]: ErrorCapturingFunction<T[K]>;
|
||||
};
|
||||
|
||||
declare interface ErrorCapturingSqlMigrationAwareDriverAdapterFactory extends ErrorCapturingInterface<SqlMigrationAwareDriverAdapterFactory> {
|
||||
readonly errorRegistry: ErrorRegistry;
|
||||
}
|
||||
|
||||
declare type ErrorRecord = {
|
||||
error: unknown;
|
||||
};
|
||||
|
||||
declare interface ErrorRegistry {
|
||||
consumeError(id: number): ErrorRecord | undefined;
|
||||
}
|
||||
|
||||
declare type IsolationLevel = 'READ UNCOMMITTED' | 'READ COMMITTED' | 'REPEATABLE READ' | 'SNAPSHOT' | 'SERIALIZABLE';
|
||||
|
||||
/**
|
||||
* Load a Prisma config file from the given directory.
|
||||
* This function may fail, but it will never throw.
|
||||
* The possible error is returned in the result object, so the caller can handle it as needed.
|
||||
*/
|
||||
export declare function loadConfigFromFile({ configFile, configRoot, }: LoadConfigFromFileInput): Promise<ConfigFromFile>;
|
||||
|
||||
export declare type LoadConfigFromFileError = {
|
||||
_tag: 'ConfigFileNotFound';
|
||||
} | {
|
||||
_tag: 'TypeScriptImportFailed';
|
||||
error: Error;
|
||||
} | {
|
||||
_tag: 'ConfigFileParseError';
|
||||
error: Error;
|
||||
} | {
|
||||
_tag: 'UnknownError';
|
||||
error: Error;
|
||||
};
|
||||
|
||||
declare type LoadConfigFromFileInput = {
|
||||
/**
|
||||
* The path to the config file to load. If not provided, we will attempt to find a config file in the `configRoot` directory.
|
||||
*/
|
||||
configFile?: string;
|
||||
/**
|
||||
* The directory to search for the config file in. Defaults to the current working directory.
|
||||
*/
|
||||
configRoot?: string;
|
||||
};
|
||||
|
||||
declare const officialPrismaAdapters: readonly ["@prisma/adapter-planetscale", "@prisma/adapter-neon", "@prisma/adapter-libsql", "@prisma/adapter-d1", "@prisma/adapter-pg", "@prisma/adapter-pg-worker"];
|
||||
|
||||
declare const PRISMA_CONFIG_INTERNAL_BRAND: unique symbol;
|
||||
|
||||
/**
|
||||
* The configuration for the Prisma Development Kit, before it is passed to the `defineConfig` function.
|
||||
* Thanks to the branding, this type is opaque and cannot be constructed directly.
|
||||
*/
|
||||
export declare type PrismaConfig<Env extends EnvVars = never> = {
|
||||
/**
|
||||
* Whether features with an unstable API are enabled.
|
||||
*/
|
||||
earlyAccess: true;
|
||||
/**
|
||||
* The path to the schema file or path to a folder that shall be recursively searched for .prisma files.
|
||||
*/
|
||||
schema?: string;
|
||||
/**
|
||||
* The configuration for Prisma Studio.
|
||||
*/
|
||||
studio?: PrismaStudioConfigShape<Env>;
|
||||
/**
|
||||
* The configuration for Prisma Migrate + Introspect
|
||||
*/
|
||||
migrate?: PrismaMigrateConfigShape<Env>;
|
||||
};
|
||||
|
||||
/**
|
||||
* The configuration for the Prisma Development Kit, after it has been parsed and processed
|
||||
* by the `defineConfig` function.
|
||||
* Thanks to the branding, this type is opaque and cannot be constructed directly.
|
||||
*/
|
||||
export declare type PrismaConfigInternal<Env extends EnvVars = never> = _PrismaConfigInternal<Env> & {
|
||||
__brand: typeof PRISMA_CONFIG_INTERNAL_BRAND;
|
||||
};
|
||||
|
||||
declare type _PrismaConfigInternal<Env extends EnvVars = never> = {
|
||||
/**
|
||||
* Whether features with an unstable API are enabled.
|
||||
*/
|
||||
earlyAccess: true;
|
||||
/**
|
||||
* The path to the schema file or path to a folder that shall be recursively searched for .prisma files.
|
||||
*/
|
||||
schema?: string;
|
||||
/**
|
||||
* The configuration for Prisma Studio.
|
||||
*/
|
||||
studio?: PrismaStudioConfigShape<Env>;
|
||||
/**
|
||||
* The configuration for Prisma Migrate + Introspect
|
||||
*/
|
||||
migrate?: PrismaMigrateConfigInternalShape<Env>;
|
||||
/**
|
||||
* The path from where the config was loaded.
|
||||
* It's set to `null` if no config file was found and only default config is applied.
|
||||
*/
|
||||
loadedFromFile: string | null;
|
||||
};
|
||||
|
||||
declare type PrismaMigrateConfigInternalShape<Env extends EnvVars = never> = {
|
||||
adapter: (env: Env) => Promise<ErrorCapturingSqlMigrationAwareDriverAdapterFactory>;
|
||||
};
|
||||
|
||||
declare type PrismaMigrateConfigShape<Env extends EnvVars = never> = {
|
||||
adapter: (env: Env) => Promise<SqlMigrationAwareDriverAdapterFactory>;
|
||||
};
|
||||
|
||||
declare type PrismaStudioConfigShape<Env extends EnvVars = never> = {
|
||||
adapter: (env: Env) => Promise<SqlMigrationAwareDriverAdapterFactory>;
|
||||
};
|
||||
|
||||
declare type Provider = 'mysql' | 'postgres' | 'sqlite';
|
||||
|
||||
declare interface Queryable<Query, Result> extends AdapterInfo {
|
||||
/**
|
||||
* Execute a query and return its result.
|
||||
*/
|
||||
queryRaw(params: Query): Promise<Result>;
|
||||
/**
|
||||
* Execute a query and return the number of affected rows.
|
||||
*/
|
||||
executeRaw(params: Query): Promise<number>;
|
||||
}
|
||||
|
||||
declare type Result<T> = {
|
||||
map<U>(fn: (value: T) => U): Result<U>;
|
||||
flatMap<U>(fn: (value: T) => Result<U>): Result<U>;
|
||||
} & ({
|
||||
readonly ok: true;
|
||||
readonly value: T;
|
||||
} | {
|
||||
readonly ok: false;
|
||||
readonly error: Error_2;
|
||||
});
|
||||
|
||||
declare interface SqlDriverAdapter extends SqlQueryable {
|
||||
/**
|
||||
* Execute multiple SQL statements separated by semicolon.
|
||||
*/
|
||||
executeScript(script: string): Promise<void>;
|
||||
/**
|
||||
* Start new transaction.
|
||||
*/
|
||||
startTransaction(isolationLevel?: IsolationLevel): Promise<Transaction>;
|
||||
/**
|
||||
* Optional method that returns extra connection info
|
||||
*/
|
||||
getConnectionInfo?(): ConnectionInfo;
|
||||
/**
|
||||
* Dispose of the connection and release any resources.
|
||||
*/
|
||||
dispose(): Promise<void>;
|
||||
}
|
||||
|
||||
declare interface SqlDriverAdapterFactory extends DriverAdapterFactory<SqlQuery, SqlResultSet> {
|
||||
connect(): Promise<SqlDriverAdapter>;
|
||||
}
|
||||
|
||||
/**
|
||||
* An SQL migration adapter that is aware of the notion of a shadow database
|
||||
* and can create a connection to it.
|
||||
*/
|
||||
declare interface SqlMigrationAwareDriverAdapterFactory extends SqlDriverAdapterFactory {
|
||||
connectToShadowDb(): Promise<SqlDriverAdapter>;
|
||||
}
|
||||
|
||||
declare type SqlQuery = {
|
||||
sql: string;
|
||||
args: Array<unknown>;
|
||||
argTypes: Array<ArgType>;
|
||||
};
|
||||
|
||||
declare interface SqlQueryable extends Queryable<SqlQuery, SqlResultSet> {
|
||||
}
|
||||
|
||||
declare interface SqlResultSet {
|
||||
/**
|
||||
* List of column types appearing in a database query, in the same order as `columnNames`.
|
||||
* They are used within the Query Engine to convert values from JS to Quaint values.
|
||||
*/
|
||||
columnTypes: Array<ColumnType>;
|
||||
/**
|
||||
* List of column names appearing in a database query, in the same order as `columnTypes`.
|
||||
*/
|
||||
columnNames: Array<string>;
|
||||
/**
|
||||
* List of rows retrieved from a database query.
|
||||
* Each row is a list of values, whose length matches `columnNames` and `columnTypes`.
|
||||
*/
|
||||
rows: Array<Array<unknown>>;
|
||||
/**
|
||||
* The last ID of an `INSERT` statement, if any.
|
||||
* This is required for `AUTO_INCREMENT` columns in databases based on MySQL and SQLite.
|
||||
*/
|
||||
lastInsertId?: string;
|
||||
}
|
||||
|
||||
declare interface Transaction extends AdapterInfo, SqlQueryable {
|
||||
/**
|
||||
* Transaction options.
|
||||
*/
|
||||
readonly options: TransactionOptions;
|
||||
/**
|
||||
* Commit the transaction.
|
||||
*/
|
||||
commit(): Promise<void>;
|
||||
/**
|
||||
* Roll back the transaction.
|
||||
*/
|
||||
rollback(): Promise<void>;
|
||||
}
|
||||
|
||||
declare type TransactionOptions = {
|
||||
usePhantomQuery: boolean;
|
||||
};
|
||||
|
||||
export { }
|
||||
+22760
File diff suppressed because it is too large
Load Diff
+1
@@ -0,0 +1 @@
|
||||
../jiti/lib/jiti-cli.mjs
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Pooya Parsa <pooya@pi0.io>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+235
@@ -0,0 +1,235 @@
|
||||
# jiti
|
||||
|
||||
<!-- automd:badges color=F0DB4F bundlephobia -->
|
||||
|
||||
[](https://npmjs.com/package/jiti)
|
||||
[](https://npmjs.com/package/jiti)
|
||||
[](https://bundlephobia.com/package/jiti)
|
||||
|
||||
<!-- /automd -->
|
||||
|
||||
> This is the active development branch. Check out [jiti/v1](https://github.com/unjs/jiti/tree/v1) for legacy v1 docs and code.
|
||||
|
||||
## 🌟 Used in
|
||||
|
||||
[Docusaurus](https://docusaurus.io/), [ESLint](https://github.com/eslint/eslint), [FormKit](https://formkit.com/), [Histoire](https://histoire.dev/), [Knip](https://knip.dev/), [Nitro](https://nitro.unjs.io/), [Nuxt](https://nuxt.com/), [PostCSS loader](https://github.com/webpack-contrib/postcss-loader), [Rsbuild](https://rsbuild.dev/), [Size Limit](https://github.com/ai/size-limit), [Slidev](https://sli.dev/), [Tailwindcss](https://tailwindcss.com/), [Tokenami](https://github.com/tokenami/tokenami), [UnoCSS](https://unocss.dev/), [WXT](https://wxt.dev/), [Winglang](https://www.winglang.io/), [Graphql code generator](https://the-guild.dev/graphql/codegen), [Lingui](https://lingui.dev/), [Scaffdog](https://scaff.dog/), [Storybook](https://storybook.js.org), [...UnJS ecosystem](https://unjs.io/), [...60M+ npm monthly downloads](https://npm.chart.dev/jiti), [...6M+ public repositories](https://github.com/unjs/jiti/network/dependents).
|
||||
|
||||
## ✅ Features
|
||||
|
||||
- Seamless TypeScript and ESM syntax support for Node.js
|
||||
- Seamless interoperability between ESM and CommonJS
|
||||
- Asynchronous API to replace `import()`
|
||||
- Synchronous API to replace `require()` (deprecated)
|
||||
- Super slim and zero dependency
|
||||
- Custom resolve aliases
|
||||
- Smart syntax detection to avoid extra transforms
|
||||
- Node.js native `require.cache` integration
|
||||
- Filesystem transpile with hard disk caches
|
||||
- ESM Loader support
|
||||
- JSX support (opt-in)
|
||||
|
||||
> [!IMPORTANT]
|
||||
> To enhance compatibility, jiti `>=2.1` enabled [`interopdefault`](#interopdefault) using a new Proxy method. If you migrated to `2.0.0` earlier, this might have caused behavior changes. In case of any issues during the upgrade, please [report](https://github.com/unjs/jiti/issues) so we can investigate to solve them. 🙏🏼
|
||||
|
||||
## 💡 Usage
|
||||
|
||||
### CLI
|
||||
|
||||
You can use `jiti` CLI to quickly run any script with TypeScript and native ESM support!
|
||||
|
||||
```bash
|
||||
npx jiti ./index.ts
|
||||
```
|
||||
|
||||
### Programmatic
|
||||
|
||||
Initialize a jiti instance:
|
||||
|
||||
```js
|
||||
// ESM
|
||||
import { createJiti } from "jiti";
|
||||
const jiti = createJiti(import.meta.url);
|
||||
|
||||
// CommonJS (deprecated)
|
||||
const { createJiti } = require("jiti");
|
||||
const jiti = createJiti(__filename);
|
||||
```
|
||||
|
||||
Import (async) and resolve with ESM compatibility:
|
||||
|
||||
```js
|
||||
// jiti.import(id) is similar to import(id)
|
||||
const mod = await jiti.import("./path/to/file.ts");
|
||||
|
||||
// jiti.esmResolve(id) is similar to import.meta.resolve(id)
|
||||
const resolvedPath = jiti.esmResolve("./src");
|
||||
```
|
||||
|
||||
If you need the default export of module, you can use `jiti.import(id, { default: true })` as shortcut to `mod?.default ?? mod`.
|
||||
|
||||
```js
|
||||
// shortcut to mod?.default ?? mod
|
||||
const modDefault = await jiti.import("./path/to/file.ts", { default: true });
|
||||
```
|
||||
|
||||
CommonJS (sync & deprecated):
|
||||
|
||||
```js
|
||||
// jiti() is similar to require(id)
|
||||
const mod = jiti("./path/to/file.ts");
|
||||
|
||||
// jiti.resolve() is similar to require.resolve(id)
|
||||
const resolvedPath = jiti.resolve("./src");
|
||||
```
|
||||
|
||||
You can also pass options as the second argument:
|
||||
|
||||
```js
|
||||
const jiti = createJiti(import.meta.url, { debug: true });
|
||||
```
|
||||
|
||||
### Register global ESM loader
|
||||
|
||||
You can globally register jiti using [global hooks](https://nodejs.org/api/module.html#initialize). (Important: Requires Node.js > 20)
|
||||
|
||||
```js
|
||||
import "jiti/register";
|
||||
```
|
||||
|
||||
Or:
|
||||
|
||||
```bash
|
||||
node --import jiti/register index.ts
|
||||
```
|
||||
|
||||
## 🎈 `jiti/native`
|
||||
|
||||
You can alias `jiti` to `jiti/native` to directly depend on runtime's [`import.meta.resolve`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta/resolve) and dynamic [`import()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import) support. This allows easing up the ecosystem transition to runtime native support by giving the same API of jiti.
|
||||
|
||||
## ⚙️ Options
|
||||
|
||||
### `debug`
|
||||
|
||||
- Type: Boolean
|
||||
- Default: `false`
|
||||
- Environment variable: `JITI_DEBUG`
|
||||
|
||||
Enable verbose logging. You can use `JITI_DEBUG=1 <your command>` to enable it.
|
||||
|
||||
### `fsCache`
|
||||
|
||||
- Type: Boolean | String
|
||||
- Default: `true`
|
||||
- Environment variable: `JITI_FS_CACHE`
|
||||
|
||||
Filesystem source cache (enabled by default)
|
||||
|
||||
By default (when is `true`), jiti uses `node_modules/.cache/jiti` (if exists) or `{TMP_DIR}/jiti`.
|
||||
|
||||
**Note:** It is recommended that this option be enabled for better performance.
|
||||
|
||||
### `moduleCache`
|
||||
|
||||
- Type: String
|
||||
- Default: `true`
|
||||
- Environment variable: `JITI_MODULE_CACHE`
|
||||
|
||||
Runtime module cache (enabled by default).
|
||||
|
||||
Disabling allows editing code and importing the same module multiple times.
|
||||
|
||||
When enabled, jiti integrates with Node.js native CommonJS cache-store.
|
||||
|
||||
### `transform`
|
||||
|
||||
- Type: Function
|
||||
- Default: Babel (lazy loaded)
|
||||
|
||||
Transform function. See [src/babel](./src/babel.ts) for more details
|
||||
|
||||
### `sourceMaps`
|
||||
|
||||
- Type: Boolean
|
||||
- Default `false`
|
||||
- Environment variable: `JITI_SOURCE_MAPS`
|
||||
|
||||
Add inline source map to transformed source for better debugging.
|
||||
|
||||
### `interopDefault`
|
||||
|
||||
- Type: Boolean
|
||||
- Default: `true`
|
||||
- Environment variable: `JITI_INTEROP_DEFAULT`
|
||||
|
||||
Jiti combines module exports with the `default` export using an internal Proxy to improve compatibility with mixed CJS/ESM usage. You can check the current implementation [here](https://github.com/unjs/jiti/blob/main/src/utils.ts#L105).
|
||||
|
||||
### `alias`
|
||||
|
||||
- Type: Object
|
||||
- Default: -
|
||||
- Environment variable: `JITI_ALIAS`
|
||||
|
||||
You can also pass an object to the environment variable for inline config. Example: `JITI_ALIAS='{"~/*": "./src/*"}' jiti ...`.
|
||||
|
||||
Custom alias map used to resolve IDs.
|
||||
|
||||
### `nativeModules`
|
||||
|
||||
- Type: Array
|
||||
- Default: ['typescript']
|
||||
- Environment variable: `JITI_NATIVE_MODULES`
|
||||
|
||||
List of modules (within `node_modules`) to always use native `require()` for them.
|
||||
|
||||
### `transformModules`
|
||||
|
||||
- Type: Array
|
||||
- Default: []
|
||||
- Environment variable: `JITI_TRANSFORM_MODULES`
|
||||
|
||||
List of modules (within `node_modules`) to transform them regardless of syntax.
|
||||
|
||||
### `importMeta`
|
||||
|
||||
Parent module's [`import.meta`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta) context to use for ESM resolution. (only used for `jiti/native` import).
|
||||
|
||||
### `tryNative`
|
||||
|
||||
- Type: Boolean
|
||||
- Default: Enabled if bun is detected
|
||||
- Environment variable: `JITI_TRY_NATIVE`
|
||||
|
||||
Try to use native require and import without jiti transformations first.
|
||||
|
||||
### `jsx`
|
||||
|
||||
- Type: Boolean | {options}
|
||||
- Default: `false`
|
||||
- Environment Variable: `JITI_JSX`
|
||||
|
||||
Enable JSX support using [`@babel/plugin-transform-react-jsx`](https://babeljs.io/docs/babel-plugin-transform-react-jsx).
|
||||
|
||||
See [`test/fixtures/jsx`](./test/fixtures/jsx) for framework integration examples.
|
||||
|
||||
## Development
|
||||
|
||||
- Clone this repository
|
||||
- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable`
|
||||
- Install dependencies using `pnpm install`
|
||||
- Run `pnpm dev`
|
||||
- Run `pnpm jiti ./test/path/to/file.ts`
|
||||
|
||||
## License
|
||||
|
||||
<!-- automd:contributors license=MIT author="pi0" -->
|
||||
|
||||
Published under the [MIT](https://github.com/unjs/jiti/blob/main/LICENSE) license.
|
||||
Made by [@pi0](https://github.com/pi0) and [community](https://github.com/unjs/jiti/graphs/contributors) 💛
|
||||
<br><br>
|
||||
<a href="https://github.com/unjs/jiti/graphs/contributors">
|
||||
<img src="https://contrib.rocks/image?repo=unjs/jiti" />
|
||||
</a>
|
||||
|
||||
<!-- /automd -->
|
||||
|
||||
<!-- automd:with-automd -->
|
||||
+246
File diff suppressed because one or more lines are too long
+1
File diff suppressed because one or more lines are too long
+34
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { resolve } from "node:path";
|
||||
import nodeModule from "node:module";
|
||||
|
||||
const script = process.argv.splice(2, 1)[0];
|
||||
|
||||
if (!script) {
|
||||
console.error("Usage: jiti <path> [...arguments]");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// https://nodejs.org/api/module.html#moduleenablecompilecachecachedir
|
||||
// https://github.com/nodejs/node/pull/54501
|
||||
if (nodeModule.enableCompileCache && !process.env.NODE_DISABLE_COMPILE_CACHE) {
|
||||
try {
|
||||
nodeModule.enableCompileCache();
|
||||
} catch {
|
||||
// Ignore errors
|
||||
}
|
||||
}
|
||||
|
||||
const pwd = process.cwd();
|
||||
|
||||
const { createJiti } = await import("./jiti.cjs");
|
||||
|
||||
const jiti = createJiti(pwd);
|
||||
|
||||
const resolved = (process.argv[1] = jiti.resolve(resolve(pwd, script)));
|
||||
|
||||
await jiti.import(resolved).catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
import { dirname, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { existsSync } from "node:fs";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { isBuiltin } from "node:module";
|
||||
import { createJiti } from "./jiti.mjs";
|
||||
|
||||
let jiti;
|
||||
|
||||
// https://nodejs.org/api/module.html#initialize
|
||||
export async function initialize() {
|
||||
jiti = createJiti();
|
||||
}
|
||||
|
||||
// https://nodejs.org/api/module.html#resolvespecifier-context-nextresolve
|
||||
export async function resolve(specifier, context, nextResolve) {
|
||||
if (_shouldSkip(specifier)) {
|
||||
return nextResolve(specifier, context);
|
||||
}
|
||||
const resolvedPath = jiti.esmResolve(specifier, {
|
||||
parentURL: context?.parentURL,
|
||||
conditions: context?.conditions,
|
||||
});
|
||||
return {
|
||||
url: resolvedPath,
|
||||
shortCircuit: true,
|
||||
};
|
||||
}
|
||||
|
||||
// https://nodejs.org/api/module.html#loadurl-context-nextload
|
||||
export async function load(url, context, nextLoad) {
|
||||
if (_shouldSkip(url)) {
|
||||
return nextLoad(url, context);
|
||||
}
|
||||
|
||||
const filename = fileURLToPath(url);
|
||||
|
||||
if (url.endsWith(".js")) {
|
||||
const pkg = await _findClosestPackageJson(dirname(filename));
|
||||
if (pkg && pkg.type === "module") {
|
||||
return nextLoad(url, context);
|
||||
}
|
||||
}
|
||||
|
||||
const rawSource = await readFile(filename, "utf8");
|
||||
|
||||
if (url.endsWith(".json")) {
|
||||
return {
|
||||
source: `export default ${rawSource}`,
|
||||
format: "module",
|
||||
shortCircuit: true,
|
||||
};
|
||||
}
|
||||
|
||||
const transpiledSource = jiti.transform({
|
||||
source: rawSource,
|
||||
filename: filename,
|
||||
ts: url.endsWith("ts"),
|
||||
retainLines: true,
|
||||
async: true,
|
||||
jsx: jiti.options.jsx,
|
||||
});
|
||||
|
||||
if (url.endsWith(".js") && !transpiledSource.includes("jitiImport")) {
|
||||
return {
|
||||
source: transpiledSource,
|
||||
format: "commonjs",
|
||||
shortCircuit: true,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
source: _wrapSource(transpiledSource, filename),
|
||||
format: "module",
|
||||
shortCircuit: true,
|
||||
};
|
||||
}
|
||||
|
||||
function _wrapSource(source, filename) {
|
||||
const _jitiPath = new URL("jiti.mjs", import.meta.url).href;
|
||||
return /*js*/ `import { createJiti as __createJiti__ } from ${JSON.stringify(_jitiPath)};async function _module(exports, require, module, __filename, __dirname, jitiImport) { ${source}\n};
|
||||
// GENERATED BY JITI ESM LOADER
|
||||
const filename = ${JSON.stringify(filename)};
|
||||
const dirname = ${JSON.stringify(dirname(filename))};
|
||||
const jiti = __createJiti__(filename);
|
||||
const module = { exports: Object.create(null) };
|
||||
await _module(module.exports, jiti, module, filename, dirname, jiti.import);
|
||||
if (module.exports && module.exports.__JITI_ERROR__) {
|
||||
const { filename, line, column, code, message } =
|
||||
module.exports.__JITI_ERROR__;
|
||||
const loc = [filename, line, column].join(':');
|
||||
const err = new Error(code + ": " + message + " " + loc);
|
||||
Error.captureStackTrace(err, _module);
|
||||
throw err;
|
||||
}
|
||||
export default module.exports;
|
||||
`;
|
||||
}
|
||||
|
||||
function _shouldSkip(url) {
|
||||
return (
|
||||
!jiti ||
|
||||
url.endsWith(".mjs") ||
|
||||
url.endsWith(".cjs") ||
|
||||
(!url.startsWith("./") && !url.startsWith("file://")) ||
|
||||
isBuiltin(url)
|
||||
);
|
||||
}
|
||||
|
||||
async function _findClosestPackageJson(dir) {
|
||||
if (dir === "/") return null;
|
||||
const packageJsonPath = join(dir, "package.json");
|
||||
if (existsSync(packageJsonPath)) {
|
||||
return JSON.parse(await readFile(packageJsonPath, "utf8"));
|
||||
}
|
||||
return _findClosestPackageJson(dirname(dir));
|
||||
}
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
/**
|
||||
* @typedef {import('./types').Jiti} Jiti
|
||||
* @typedef {import('./types').JitiOptions} JitiOptions
|
||||
*/
|
||||
|
||||
const isDeno = "Deno" in globalThis;
|
||||
|
||||
/**
|
||||
* @param {string|URL} [parentURL]
|
||||
* @param {JitiOptions} [jitiOptions]
|
||||
* @returns {Jiti}
|
||||
*/
|
||||
export function createJiti(parentURL, jitiOptions) {
|
||||
parentURL = normalizeParentURL(parentURL);
|
||||
|
||||
/** @type {Jiti} */
|
||||
function jiti() {
|
||||
throw unsupportedError(
|
||||
"`jiti()` is not supported in native mode, use `jiti.import()` instead.",
|
||||
);
|
||||
}
|
||||
|
||||
jiti.resolve = () => {
|
||||
throw unsupportedError("`jiti.resolve()` is not supported in native mode.");
|
||||
};
|
||||
|
||||
jiti.esmResolve = (id, opts) => {
|
||||
try {
|
||||
const importMeta = jitiOptions?.importMeta || import.meta;
|
||||
if (isDeno) {
|
||||
// Deno throws TypeError: Invalid arguments when passing parentURL
|
||||
return importMeta.resolve(id);
|
||||
}
|
||||
const parent = normalizeParentURL(opts?.parentURL || parentURL);
|
||||
return importMeta.resolve(id, parent);
|
||||
} catch (error) {
|
||||
if (opts?.try) {
|
||||
return undefined;
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
jiti.import = async function (id, opts) {
|
||||
for (const suffix of ["", "/index"]) {
|
||||
// prettier-ignore
|
||||
for (const ext of ["", ".js", ".mjs", ".cjs", ".ts", ".tsx", ".mts", ".cts"]) {
|
||||
try {
|
||||
const resolved = this.esmResolve(id + suffix + ext, opts);
|
||||
if (!resolved) {
|
||||
continue;
|
||||
}
|
||||
let importAttrs = undefined
|
||||
if (resolved.endsWith('.json')) {
|
||||
importAttrs = { with: { type: 'json'}}
|
||||
}
|
||||
return await import(resolved, importAttrs);
|
||||
} catch (error) {
|
||||
if (error.code === 'ERR_MODULE_NOT_FOUND' || error.code === 'ERR_UNSUPPORTED_DIR_IMPORT') {
|
||||
continue
|
||||
}
|
||||
if (opts?.try) {
|
||||
return undefined;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!opts?.try) {
|
||||
const parent = normalizeParentURL(opts?.parentURL || parentURL);
|
||||
const error = new Error(
|
||||
`[jiti] [ERR_MODULE_NOT_FOUND] Cannot import '${id}' from '${parent}'.`,
|
||||
);
|
||||
error.code = "ERR_MODULE_NOT_FOUND";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
jiti.transform = () => {
|
||||
throw unsupportedError(
|
||||
"`jiti.transform()` is not supported in native mode.",
|
||||
);
|
||||
};
|
||||
|
||||
jiti.evalModule = () => {
|
||||
throw unsupportedError(
|
||||
"`jiti.evalModule()` is not supported in native mode.",
|
||||
);
|
||||
};
|
||||
|
||||
jiti.main = undefined;
|
||||
jiti.extensions = Object.create(null);
|
||||
jiti.cache = Object.create(null);
|
||||
|
||||
return jiti;
|
||||
}
|
||||
|
||||
export default createJiti;
|
||||
|
||||
/**
|
||||
* @param {string} message
|
||||
*/
|
||||
function unsupportedError(message) {
|
||||
throw new Error(
|
||||
`[jiti] ${message} (import or require 'jiti' instead of 'jiti/native' for more features).`,
|
||||
);
|
||||
}
|
||||
|
||||
function normalizeParentURL(input) {
|
||||
if (!input) {
|
||||
return "file:///";
|
||||
}
|
||||
if (typeof filename !== "string" || input.startsWith("file://")) {
|
||||
return input;
|
||||
}
|
||||
if (input.endsWith("/")) {
|
||||
input += "_"; // append a dummy filename
|
||||
}
|
||||
return `file://${input}`;
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
// eslint-disable-next-line unicorn/no-empty-file
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// https://nodejs.org/api/module.html#moduleregisterspecifier-parenturl-options
|
||||
import { register } from "node:module";
|
||||
|
||||
register("./jiti-hooks.mjs", import.meta.url, {});
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
const { createRequire } = require("node:module");
|
||||
const _createJiti = require("../dist/jiti.cjs");
|
||||
const transform = require("../dist/babel.cjs");
|
||||
|
||||
function onError(err) {
|
||||
throw err; /* ↓ Check stack trace ↓ */
|
||||
}
|
||||
|
||||
const nativeImport = (id) => import(id);
|
||||
|
||||
function createJiti(id, opts = {}) {
|
||||
if (!opts.transform) {
|
||||
opts = { ...opts, transform };
|
||||
}
|
||||
return _createJiti(id, opts, {
|
||||
onError,
|
||||
nativeImport,
|
||||
createRequire,
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = createJiti;
|
||||
module.exports.createJiti = createJiti;
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import * as types from "./types.js";
|
||||
declare const allExports: typeof types & {
|
||||
/**
|
||||
* @deprecated Please use `const { createJiti } = require("jiti")` or use ESM import.
|
||||
*/
|
||||
(...args: Parameters<typeof types.createJiti>): types.Jiti;
|
||||
};
|
||||
export = allExports;
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import { createJiti } from "./types.js";
|
||||
|
||||
export * from "./types.js";
|
||||
|
||||
/**
|
||||
* @deprecated Please use `import { createJiti } from "jiti"`
|
||||
*/
|
||||
export default createJiti;
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
import { createRequire } from "node:module";
|
||||
import _createJiti from "../dist/jiti.cjs";
|
||||
import transform from "../dist/babel.cjs";
|
||||
|
||||
function onError(err) {
|
||||
throw err; /* ↓ Check stack trace ↓ */
|
||||
}
|
||||
|
||||
const nativeImport = (id) => import(id);
|
||||
|
||||
export function createJiti(id, opts = {}) {
|
||||
if (!opts.transform) {
|
||||
opts = { ...opts, transform };
|
||||
}
|
||||
return _createJiti(id, opts, {
|
||||
onError,
|
||||
nativeImport,
|
||||
createRequire,
|
||||
});
|
||||
}
|
||||
|
||||
export default createJiti;
|
||||
+260
@@ -0,0 +1,260 @@
|
||||
export declare function createJiti(id: string, userOptions?: JitiOptions): Jiti;
|
||||
|
||||
/**
|
||||
* Jiti instance
|
||||
*
|
||||
* Calling jiti() is similar to CommonJS require() but adds extra features such as Typescript and ESM compatibility.
|
||||
*
|
||||
* **Note:**It is recommended to use `await jiti.import` instead
|
||||
*/
|
||||
export interface Jiti extends NodeRequire {
|
||||
/**
|
||||
* Resolved options
|
||||
*/
|
||||
options: JitiOptions;
|
||||
|
||||
/**
|
||||
* ESM import a module with additional Typescript and ESM compatibility.
|
||||
*
|
||||
* If you need the default export of module, you can use `jiti.import(id, { default: true })` as shortcut to `mod?.default ?? mod`.
|
||||
*/
|
||||
import<T = unknown>(
|
||||
id: string,
|
||||
opts?: JitiResolveOptions & { default?: true },
|
||||
): Promise<T>;
|
||||
|
||||
/**
|
||||
* Resolve with ESM import conditions.
|
||||
*/
|
||||
esmResolve(id: string, parentURL?: string): string;
|
||||
esmResolve<T extends JitiResolveOptions = JitiResolveOptions>(
|
||||
id: string,
|
||||
opts?: T,
|
||||
): T["try"] extends true ? string | undefined : string;
|
||||
|
||||
/**
|
||||
* Transform source code
|
||||
*/
|
||||
transform: (opts: TransformOptions) => string;
|
||||
|
||||
/**
|
||||
* Evaluate transformed code as a module
|
||||
*/
|
||||
evalModule: (source: string, options?: EvalModuleOptions) => unknown;
|
||||
}
|
||||
|
||||
/**
|
||||
* Jiti instance options
|
||||
*/
|
||||
export interface JitiOptions {
|
||||
/**
|
||||
* Filesystem source cache (enabled by default)
|
||||
*
|
||||
* An string can be passed to set the custom cache directory.
|
||||
*
|
||||
* By default (when is `true`), jiti uses `node_modules/.cache/jiti` (if exists) or `{TMP_DIR}/jiti`.
|
||||
*
|
||||
* This option can also be disabled using `JITI_FS_CACHE=false` environment variable.
|
||||
*
|
||||
* **Note:** It is recommended to keep this option enabled for better performance.
|
||||
*/
|
||||
fsCache?: boolean | string;
|
||||
|
||||
/** @deprecated Use `fsCache` option. */
|
||||
cache?: boolean | string;
|
||||
|
||||
/**
|
||||
* Runtime module cache (enabled by default)
|
||||
*
|
||||
* Disabling allows editing code and importing same module multiple times.
|
||||
*
|
||||
* When enabled, jiti integrates with Node.js native CommonJS cache store.
|
||||
*
|
||||
* This option can also be disabled using `JITI_MODULE_CACHE=false` environment variable.
|
||||
*/
|
||||
moduleCache?: boolean;
|
||||
|
||||
/** @deprecated Use `moduleCache` option. */
|
||||
requireCache?: boolean;
|
||||
|
||||
/**
|
||||
* Custom transform function
|
||||
*/
|
||||
transform?: (opts: TransformOptions) => TransformResult;
|
||||
|
||||
/**
|
||||
* Enable verbose debugging (disabled by default).
|
||||
*
|
||||
* Can also be enabled using `JITI_DEBUG=1` environment variable.
|
||||
*/
|
||||
debug?: boolean;
|
||||
|
||||
/**
|
||||
* Enable sourcemaps (enabled by default)
|
||||
*
|
||||
* Can also be disabled using `JITI_SOURCE_MAPS=0` environment variable.
|
||||
*/
|
||||
sourceMaps?: boolean;
|
||||
|
||||
/**
|
||||
* Jiti combines module exports with the `default` export using an internal Proxy to improve compatibility with mixed CJS/ESM usage. You can check the current implementation [here](https://github.com/unjs/jiti/blob/main/src/utils.ts#L105).
|
||||
*
|
||||
* Can be disabled using `JITI_INTEROP_DEFAULT=0` environment variable.
|
||||
*/
|
||||
interopDefault?: boolean;
|
||||
|
||||
/**
|
||||
* Jiti hard source cache version (internal)
|
||||
*/
|
||||
cacheVersion?: string;
|
||||
|
||||
/**
|
||||
* Supported extensions to resolve.
|
||||
*
|
||||
* Default `[".js", ".mjs", ".cjs", ".ts", ".mts", ".cts", ".json"]`
|
||||
*/
|
||||
extensions?: string[];
|
||||
|
||||
/**
|
||||
* Transform options
|
||||
*/
|
||||
transformOptions?: Omit<TransformOptions, "source">;
|
||||
|
||||
/**
|
||||
* Resolve aliases
|
||||
*
|
||||
* You can use `JITI_ALIAS` environment variable to set aliases as a JSON string.
|
||||
*/
|
||||
alias?: Record<string, string>;
|
||||
|
||||
/**
|
||||
* List of modules (within `node_modules`) to always use native require/import for them.
|
||||
*
|
||||
* You can use `JITI_NATIVE_MODULES` environment variable to set native modules as a JSON string.
|
||||
*
|
||||
*/
|
||||
nativeModules?: string[];
|
||||
|
||||
/**
|
||||
* List of modules (within `node_modules`) to transform them regardless of syntax.
|
||||
*
|
||||
* You can use `JITI_TRANSFORM_MODULES` environment variable to set transform modules as a JSON string.
|
||||
*/
|
||||
transformModules?: string[];
|
||||
|
||||
/**
|
||||
* Parent module's import.meta context to use for ESM resolution.
|
||||
*
|
||||
* (Only used for `jiti/native` import)
|
||||
*/
|
||||
importMeta?: ImportMeta;
|
||||
|
||||
/**
|
||||
* Try to use native require and import without jiti transformations first.
|
||||
*
|
||||
* Enabled if Bun is detected.
|
||||
*/
|
||||
tryNative?: boolean;
|
||||
|
||||
/**
|
||||
* Enable JSX support Enable JSX support using [`@babel/plugin-transform-react-jsx`](https://babeljs.io/docs/babel-plugin-transform-react-jsx).
|
||||
*
|
||||
* @default false
|
||||
*
|
||||
* You can also use `JITI_JSX=1` environment variable to enable JSX support.
|
||||
*/
|
||||
jsx?: boolean | JSXOptions;
|
||||
}
|
||||
|
||||
interface NodeRequire {
|
||||
/**
|
||||
* Module cache
|
||||
*/
|
||||
cache: ModuleCache;
|
||||
|
||||
/** @deprecated Prefer `await jiti.import()` for better compatibility. */
|
||||
(id: string): any;
|
||||
|
||||
/** @deprecated Prefer `jiti.esmResolve` for better compatibility. */
|
||||
resolve: {
|
||||
/** @deprecated */
|
||||
(id: string, options?: { paths?: string[] | undefined }): string;
|
||||
/** @deprecated */
|
||||
paths(request: string): string[] | null;
|
||||
};
|
||||
|
||||
/** @deprecated CommonJS API */
|
||||
extensions: Record<
|
||||
".js" | ".json" | ".node",
|
||||
(m: NodeModule, filename: string) => any | undefined
|
||||
>;
|
||||
|
||||
/** @deprecated CommonJS API */
|
||||
main: NodeModule | undefined;
|
||||
}
|
||||
|
||||
export interface NodeModule {
|
||||
/**
|
||||
* `true` if the module is running during the Node.js preload
|
||||
*/
|
||||
isPreloading: boolean;
|
||||
exports: any;
|
||||
require: NodeRequire;
|
||||
id: string;
|
||||
filename: string;
|
||||
loaded: boolean;
|
||||
/** @deprecated since v14.6.0 Please use `require.main` and `module.children` instead. */
|
||||
parent: NodeModule | null | undefined;
|
||||
children: NodeModule[];
|
||||
/**
|
||||
* @since v11.14.0
|
||||
*
|
||||
* The directory name of the module. This is usually the same as the path.dirname() of the module.id.
|
||||
*/
|
||||
path: string;
|
||||
paths: string[];
|
||||
}
|
||||
|
||||
export type ModuleCache = Record<string, NodeModule>;
|
||||
|
||||
export type EvalModuleOptions = Partial<{
|
||||
id: string;
|
||||
filename: string;
|
||||
ext: string;
|
||||
cache: ModuleCache;
|
||||
async: boolean;
|
||||
forceTranspile: boolean;
|
||||
}>;
|
||||
|
||||
export interface TransformOptions {
|
||||
source: string;
|
||||
filename?: string;
|
||||
ts?: boolean;
|
||||
retainLines?: boolean;
|
||||
interopDefault?: boolean;
|
||||
async?: boolean;
|
||||
jsx?: boolean | JSXOptions;
|
||||
babel?: Record<string, any>;
|
||||
}
|
||||
|
||||
export interface TransformResult {
|
||||
code: string;
|
||||
error?: any;
|
||||
}
|
||||
|
||||
export interface JitiResolveOptions {
|
||||
conditions?: string[];
|
||||
parentURL?: string | URL;
|
||||
try?: boolean;
|
||||
}
|
||||
|
||||
/** Reference: https://babeljs.io/docs/babel-plugin-transform-react-jsx#options */
|
||||
export interface JSXOptions {
|
||||
throwIfNamespace?: boolean;
|
||||
runtime?: "classic" | "automatic";
|
||||
importSource?: string;
|
||||
pragma?: string;
|
||||
pragmaFrag?: string;
|
||||
useBuiltIns?: boolean;
|
||||
useSpread?: boolean;
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
{
|
||||
"name": "jiti",
|
||||
"version": "2.4.2",
|
||||
"description": "Runtime typescript and ESM support for Node.js",
|
||||
"repository": "unjs/jiti",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": {
|
||||
"types": "./lib/jiti.d.mts",
|
||||
"default": "./lib/jiti.mjs"
|
||||
},
|
||||
"require": {
|
||||
"types": "./lib/jiti.d.cts",
|
||||
"default": "./lib/jiti.cjs"
|
||||
}
|
||||
},
|
||||
"./register": {
|
||||
"types": "./lib/jiti-register.d.mts",
|
||||
"import": "./lib/jiti-register.mjs"
|
||||
},
|
||||
"./native": {
|
||||
"types": "./lib/jiti.d.mts",
|
||||
"import": "./lib/jiti-native.mjs"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"main": "./lib/jiti.cjs",
|
||||
"module": "./lib/jiti.mjs",
|
||||
"types": "./lib/jiti.d.cts",
|
||||
"typesVersions": {
|
||||
"*": {
|
||||
"register": [
|
||||
"./lib/jiti-register.d.mts"
|
||||
],
|
||||
"native": [
|
||||
"./lib/jiti.d.mts"
|
||||
]
|
||||
}
|
||||
},
|
||||
"bin": {
|
||||
"jiti": "./lib/jiti-cli.mjs"
|
||||
},
|
||||
"files": [
|
||||
"lib",
|
||||
"dist",
|
||||
"register.cjs"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "pnpm clean && NODE_ENV=production pnpm webpack",
|
||||
"clean": "rm -rf dist",
|
||||
"dev": "pnpm clean && pnpm webpack --watch",
|
||||
"jiti": "JITI_DEBUG=1 JITI_JSX=1 lib/jiti-cli.mjs",
|
||||
"lint": "eslint . && prettier -c src lib test stubs",
|
||||
"lint:fix": "eslint --fix . && prettier -w src lib test stubs",
|
||||
"prepack": "pnpm build",
|
||||
"release": "pnpm build && pnpm test && changelogen --release --push --publish",
|
||||
"test": "pnpm lint && pnpm test:types && vitest run --coverage && pnpm test:node-register && pnpm test:bun && pnpm test:native",
|
||||
"test:bun": "bun --bun test test/bun",
|
||||
"test:native": "pnpm test:native:bun && pnpm test:native:node && pnpm test:native:deno",
|
||||
"test:native:bun": "bun --bun test test/native/bun.test.ts",
|
||||
"test:native:deno": "deno test -A --no-check test/native/deno.test.ts",
|
||||
"test:native:node": "node --test --experimental-strip-types test/native/node.test.ts",
|
||||
"test:node-register": "JITI_JSX=1 node --test test/node-register.test.mjs",
|
||||
"test:types": "tsc --noEmit"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.26.0",
|
||||
"@babel/helper-module-imports": "^7.25.9",
|
||||
"@babel/helper-module-transforms": "^7.26.0",
|
||||
"@babel/helper-plugin-utils": "^7.25.9",
|
||||
"@babel/helper-simple-access": "^7.25.9",
|
||||
"@babel/plugin-proposal-decorators": "^7.25.9",
|
||||
"@babel/plugin-syntax-class-properties": "^7.12.13",
|
||||
"@babel/plugin-syntax-import-assertions": "^7.26.0",
|
||||
"@babel/plugin-syntax-jsx": "^7.25.9",
|
||||
"@babel/plugin-transform-export-namespace-from": "^7.25.9",
|
||||
"@babel/plugin-transform-react-jsx": "^7.25.9",
|
||||
"@babel/plugin-transform-typescript": "^7.26.3",
|
||||
"@babel/preset-typescript": "^7.26.0",
|
||||
"@babel/template": "^7.25.9",
|
||||
"@babel/traverse": "^7.26.4",
|
||||
"@babel/types": "^7.26.3",
|
||||
"@types/babel__core": "^7.20.5",
|
||||
"@types/babel__helper-module-imports": "^7.18.3",
|
||||
"@types/babel__helper-plugin-utils": "^7.10.3",
|
||||
"@types/babel__template": "^7.4.4",
|
||||
"@types/babel__traverse": "^7.20.6",
|
||||
"@types/node": "^22.10.2",
|
||||
"@vitest/coverage-v8": "^2.1.8",
|
||||
"acorn": "^8.14.0",
|
||||
"babel-plugin-parameter-decorator": "^1.0.16",
|
||||
"changelogen": "^0.5.7",
|
||||
"config": "^3.3.12",
|
||||
"consola": "^3.2.3",
|
||||
"defu": "^6.1.4",
|
||||
"destr": "^2.0.3",
|
||||
"escape-string-regexp": "^5.0.0",
|
||||
"eslint": "^9.17.0",
|
||||
"eslint-config-unjs": "^0.4.2",
|
||||
"estree-walker": "^3.0.3",
|
||||
"etag": "^1.8.1",
|
||||
"fast-glob": "^3.3.2",
|
||||
"is-installed-globally": "^1.0.0",
|
||||
"mime": "^4.0.4",
|
||||
"mlly": "^1.7.3",
|
||||
"moment-timezone": "^0.5.46",
|
||||
"nano-jsx": "^0.1.0",
|
||||
"pathe": "^1.1.2",
|
||||
"pkg-types": "^1.2.1",
|
||||
"preact": "^10.25.2",
|
||||
"preact-render-to-string": "^6.5.12",
|
||||
"prettier": "^3.4.2",
|
||||
"react": "^19.0.0",
|
||||
"react-dom": "^19.0.0",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"solid-js": "^1.9.3",
|
||||
"std-env": "^3.8.0",
|
||||
"terser-webpack-plugin": "^5.3.11",
|
||||
"tinyexec": "^0.3.1",
|
||||
"ts-loader": "^9.5.1",
|
||||
"typescript": "^5.7.2",
|
||||
"vitest": "^2.1.8",
|
||||
"vue": "^3.5.13",
|
||||
"webpack": "^5.97.1",
|
||||
"webpack-bundle-analyzer": "^4.10.2",
|
||||
"webpack-cli": "^5.1.4",
|
||||
"webpack-license-plugin": "^4.5.0",
|
||||
"yoctocolors": "^2.1.1",
|
||||
"zod": "^3.24.1"
|
||||
},
|
||||
"packageManager": "pnpm@9.15.0"
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"name": "@prisma/config",
|
||||
"version": "6.8.2",
|
||||
"description": "Internal package used to define and read Prisma configuration files",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/prisma/prisma.git",
|
||||
"directory": "packages/config"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"author": "Alberto Schiabel <schiabel@prisma.io>",
|
||||
"dependencies": {
|
||||
"jiti": "2.4.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@swc/core": "1.11.5",
|
||||
"@swc/jest": "0.2.37",
|
||||
"effect": "3.12.10",
|
||||
"jest": "29.7.0",
|
||||
"jest-junit": "16.0.0",
|
||||
"cross-env": "7.0.3",
|
||||
"@prisma/driver-adapter-utils": "6.8.2",
|
||||
"@prisma/get-platform": "6.8.2"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"sideEffects": false,
|
||||
"scripts": {
|
||||
"dev": "DEV=true tsx helpers/build.ts",
|
||||
"build": "tsx helpers/build.ts",
|
||||
"test": "cross-env NODE_OPTIONS='--experimental-vm-modules' jest"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user