-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split date adapters into sub packages to help with peerDependencies r…
…esolution ```diff - import { AdapterDateFns } from "@salt-ds/date-adapters"; - import { AdapterDayjs } from "@salt-ds/date-adapters"; - import { AdapterLuxon } from "@salt-ds/date-adapters"; - import { AdapterMoment } from "@salt-ds/date-adapters"; + import { AdapterDateFns } from "@salt-ds/date-adapters/date-fns"; + import { AdapterDayjs } from "@salt-ds/date-adapters/dayjs"; + import { AdapterLuxon } from "@salt-ds/date-adapters/luxon"; + import { AdapterMoment } from "@salt-ds/date-adapters/moment"; ```
- Loading branch information
Showing
29 changed files
with
281 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
import path from "node:path"; | ||
import commonjs from "@rollup/plugin-commonjs"; | ||
import json from "@rollup/plugin-json"; | ||
import { nodeResolve } from "@rollup/plugin-node-resolve"; | ||
import browserslistToEsbuild from "browserslist-to-esbuild"; | ||
import fs from "fs-extra"; | ||
import { rollup } from "rollup"; | ||
import esbuild from "rollup-plugin-esbuild"; | ||
import { makeTypings } from "./../../../scripts/makeTypings.mjs"; | ||
import { transformWorkspaceDeps } from "./../../../scripts/transformWorkspaceDeps.mjs"; | ||
import { distinct } from "./../../../scripts/utils.mjs"; | ||
|
||
const cwd = process.cwd(); | ||
|
||
const packageJson = ( | ||
await import(path.join("file://", cwd, "package.json"), { | ||
with: { type: "json" }, | ||
}) | ||
).default; | ||
|
||
const FILES_TO_COPY = ["README.md", "LICENSE", "CHANGELOG.md"].concat( | ||
packageJson.files ?? [], | ||
); | ||
|
||
const packageName = packageJson.name; | ||
const outputDir = path.join(packageJson.publishConfig.directory); | ||
|
||
console.log(`Building ${packageName}`); | ||
|
||
await fs.mkdirp(outputDir); | ||
await fs.emptyDir(outputDir); | ||
|
||
// Define entry points for each adapter | ||
const entryPoints = { | ||
types: path.join(cwd, "src/types/index.ts"), | ||
moment: path.join(cwd, "src/moment-adapter/index.ts"), | ||
luxon: path.join(cwd, "src/luxon-adapter/index.ts"), | ||
dayjs: path.join(cwd, "src/dayjs-adapter/index.ts"), | ||
"date-fns": path.join(cwd, "src/date-fns-adapter/index.ts"), | ||
}; | ||
|
||
for (const [adapterName, inputPath] of Object.entries(entryPoints)) { | ||
const entryFolder = path.basename(path.dirname(inputPath)); | ||
|
||
await makeTypings(outputDir, path.dirname(inputPath)); | ||
|
||
const bundle = await rollup({ | ||
input: inputPath, | ||
external: (id) => { | ||
if (id === "babel-plugin-transform-async-to-promises/helpers") { | ||
return false; | ||
} | ||
return !id.startsWith(".") && !path.isAbsolute(id); | ||
}, | ||
treeshake: { | ||
propertyReadSideEffects: false, | ||
}, | ||
plugins: [ | ||
nodeResolve({ | ||
extensions: [".ts", ".tsx", ".js", ".jsx"], | ||
browser: true, | ||
mainFields: ["module", "main", "browser"], | ||
}), | ||
commonjs({ include: /\/node_modules\// }), | ||
esbuild({ | ||
target: browserslistToEsbuild(), | ||
minify: false, | ||
sourceMap: true, | ||
}), | ||
json(), | ||
], | ||
}); | ||
|
||
const transformSourceMap = (relativeSourcePath, sourceMapPath) => { | ||
const absoluteSourcepath = path.resolve( | ||
path.dirname(sourceMapPath), | ||
relativeSourcePath, | ||
); | ||
const packageRelativeSourcePath = path.relative(cwd, absoluteSourcepath); | ||
|
||
return `../${packageRelativeSourcePath}`; | ||
}; | ||
|
||
await bundle.write({ | ||
freeze: false, | ||
sourcemap: true, | ||
preserveModules: false, | ||
dir: path.join(outputDir, `dist-cjs/${adapterName}`), | ||
format: "cjs", | ||
exports: "named", | ||
sourcemapPathTransform: transformSourceMap, | ||
}); | ||
|
||
await bundle.write({ | ||
freeze: false, | ||
sourcemap: true, | ||
preserveModules: false, | ||
dir: path.join(outputDir, `dist-es/${adapterName}`), | ||
format: "es", | ||
exports: "named", | ||
sourcemapPathTransform: transformSourceMap, | ||
}); | ||
|
||
await bundle.close(); | ||
} | ||
|
||
await fs.writeJSON( | ||
path.join(outputDir, "package.json"), | ||
{ | ||
...packageJson, | ||
dependencies: await transformWorkspaceDeps(packageJson.dependencies), | ||
main: "dist-cjs/index.js", | ||
module: "dist-es/index.js", | ||
typings: "dist-types/types/index.d.ts", | ||
exports: { | ||
".": { | ||
import: "./dist-es/index.js", | ||
require: "./dist-cjs/index.js", | ||
types: "./dist-types/types/index.d.ts", | ||
}, | ||
"./date-fns": { | ||
import: "./dist-es/date-fns/index.js", | ||
require: "./dist-cjs/date-fns/index.js", | ||
types: "./dist-types/date-fns-adapter/index.d.ts", | ||
}, | ||
"./dayjs": { | ||
import: "./dist-es/dayjs/index.js", | ||
require: "./dist-cjs/dayjs/index.js", | ||
types: "./dist-types/dayjs-adapter/index.d.ts", | ||
}, | ||
"./luxon": { | ||
import: "./dist-es/luxon/index.js", | ||
require: "./dist-cjs/luxon/index.js", | ||
types: "./dist-types/luxon-adapter/index.d.ts", | ||
}, | ||
"./moment": { | ||
import: "./dist-es/moment/index.js", | ||
require: "./dist-cjs/moment/index.js", | ||
types: "./dist-types/moment-adapter/index.d.ts", | ||
}, | ||
}, | ||
files: distinct([ | ||
...(packageJson.files ?? []), | ||
"dist-cjs", | ||
"dist-es", | ||
"dist-types", | ||
"CHANGELOG.md", | ||
]), | ||
}, | ||
{ spaces: 2 }, | ||
); | ||
|
||
for (const file of FILES_TO_COPY) { | ||
const filePath = path.join(cwd, file); | ||
try { | ||
await fs.copy(filePath, path.join(outputDir, file)); | ||
} catch (error) { | ||
if (error.code !== "ENOENT") { | ||
throw error; | ||
} | ||
} | ||
} | ||
|
||
console.log(`Built ${packageName} into ${outputDir}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,5 @@ | ||
/** | ||
* To add a new adapter, then, add the adapter's date object to `DateFrameworkTypeMap` interface | ||
* | ||
* declare module "./types" { | ||
* interface DateFrameworkTypeMap { | ||
* luxon: DateTime; | ||
* } | ||
* } | ||
*/ | ||
// biome-ignore lint/complexity/noBannedTypes: type augmented by configured adapters | ||
export type DateFrameworkTypeMap = {}; | ||
|
||
export * from "./date-fns"; | ||
export * from "./dayjs"; | ||
export * from "./luxon"; | ||
export * from "./moment"; | ||
|
||
export * from "./date-fns-adapter"; | ||
export * from "./dayjs-adapter"; | ||
export * from "./luxon-adapter"; | ||
export * from "./moment-adapter"; | ||
export * from "./types"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* To add a new adapter, then, add the adapter's date object to `DateFrameworkTypeMap` interface | ||
* | ||
* declare module "./types" { | ||
* interface DateFrameworkTypeMap { | ||
* luxon: DateTime; | ||
* } | ||
* } | ||
*/ | ||
|
||
// biome-ignore lint/complexity/noBannedTypes: type augmented by configured adapters | ||
export type DateFrameworkTypeMap = {}; |
1 change: 1 addition & 0 deletions
1
packages/date-adapters/src/types.ts → packages/date-adapters/src/types/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": "./src", | ||
"declaration": false, | ||
"outDir": "./dist", | ||
"module": "commonjs", | ||
"target": "es2016", | ||
"moduleResolution": "node", | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"esModuleInterop": true | ||
}, | ||
"include": ["src/**/*"] | ||
} |
10 changes: 6 additions & 4 deletions
10
packages/lab/src/__tests__/__e2e__/calendar/Calendar.a11y.cy.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 7 additions & 7 deletions
14
packages/lab/src/__tests__/__e2e__/calendar/Calendar.cy.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 7 additions & 7 deletions
14
packages/lab/src/__tests__/__e2e__/calendar/Calendar.multiselect.cy.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 7 additions & 7 deletions
14
packages/lab/src/__tests__/__e2e__/calendar/Calendar.offset.cy.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 7 additions & 7 deletions
14
packages/lab/src/__tests__/__e2e__/calendar/Calendar.single.cy.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 6 additions & 4 deletions
10
packages/lab/src/__tests__/__e2e__/date-input/DateInput.cy.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.