-
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
39 changed files
with
401 additions
and
153 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- | ||
"@salt-ds/date-adapters": patch | ||
"@salt-ds/lab": patch | ||
--- | ||
|
||
Refine peer dependency management for DatePicker adapters by splitting them into sub-packages. You now import only the specific date framework adapter you need, simplifying dependency handling. | ||
|
||
- **For `date-fns`:** | ||
|
||
```diff | ||
- import { AdapterDateFns } from "@salt-ds/date-adapters"; | ||
+ import { AdapterDateFns } from "@salt-ds/date-adapters/date-fns"; | ||
``` | ||
|
||
- **For `dayjs`:** | ||
|
||
```diff | ||
- import { AdapterDayjs } from "@salt-ds/date-adapters"; | ||
+ import { AdapterDayjs } from "@salt-ds/date-adapters/dayjs"; | ||
``` | ||
|
||
- **For `luxon`:** | ||
|
||
```diff | ||
- import { AdapterLuxon } from "@salt-ds/date-adapters"; | ||
+ import { AdapterLuxon } from "@salt-ds/date-adapters/luxon"; | ||
``` | ||
|
||
- **For `moment`:** | ||
|
||
```diff | ||
- import { AdapterMoment } from "@salt-ds/date-adapters"; | ||
+ import { AdapterMoment } from "@salt-ds/date-adapters/moment"; | ||
``` | ||
|
||
### Instructions | ||
|
||
1. Modify your import statements to use the specific sub-package for the date adapter you require. | ||
|
||
2. Ensure your `package.json` includes the necessary date framework as a dependency. For example, if using `date-fns`: | ||
|
||
```json | ||
{ | ||
"dependencies": { | ||
"date-fns": "^x.x.x" | ||
} | ||
} | ||
``` | ||
|
||
This change helps streamline the integration of date frameworks with the DatePicker component by ensuring only the necessary adapters and dependencies are included. |
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/types/index.js", | ||
require: "./dist-cjs/types/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
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
Oops, something went wrong.