-
Notifications
You must be signed in to change notification settings - Fork 5
add --preserve-extensions option
#8
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,20 +2,22 @@ import glob from "fast-glob"; | |
| import { createExports } from "./create-exports.js"; | ||
| import { createPublish } from "./create-publish.js"; | ||
| import { getJsonFormat, logger, read, write } from "./utils.js"; | ||
| import { extname } from "path"; | ||
|
|
||
| /** | ||
| * @param {object} options | ||
| * @param {string[]} options.src | ||
| * @param {string} options.main | ||
| * @param {string} options.dist | ||
| * @param {boolean} options.preserveExtensions | ||
| * @param {boolean} options.wrappers | ||
| * @param {boolean} options.workspaces | ||
| * @param {boolean} [options.publish] | ||
| * @param {boolean} [options.watch] | ||
| * @param {boolean} [options.ignoreTypes] | ||
| * @param {boolean} [options.centralizePackages] | ||
| * @param {boolean} [options.centralizeWrappers] | ||
| * @param {{src: string, snap: import("./create-exports").Pkg}} options.pkg | ||
| * @param {{src: string, snap: string}} options.pkg | ||
| */ | ||
| export async function mergeExports(options) { | ||
| logger(`getting files...`); | ||
|
|
@@ -95,6 +97,7 @@ export async function mergeExports(options) { | |
| dist: options.dist, | ||
| wrappers: options.wrappers, | ||
| ignoreTypes: options.ignoreTypes, | ||
| preserveExtensions: options.preserveExtensions, | ||
| centralizePackages: options.centralizePackages, | ||
| centralizeWrappers: options.centralizeWrappers, | ||
| }); | ||
|
|
@@ -112,6 +115,30 @@ export async function mergeExports(options) { | |
| logger(`${result.wrappers.length} wrappers created`); | ||
| } | ||
|
|
||
| if (options.preserveExtensions) { | ||
| const mappedExports = {}; | ||
| const mappedTypes = {}; | ||
|
|
||
| for (const key in result.pkg.exports) { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i used
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually, i am still getting inconsistent results. it fails about 50% of the time. there must be some kind of race condition or shared state between test runs 🤔 it's always the same failure when it happens, these two exports entries end up swapped around. but which test fails also varies. very strange - "./components/a.js": {
- "default": "./tests/module/components/a/a.js"
+ "./components/b.js": {
+ "default": "./tests/module/components/b/b.js"
},
- "./components/b.js": {
- "default": "./tests/module/components/b/b.js"
+ "./components/a.js": {
+ "default": "./tests/module/components/a/a.js"
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. even running the tests in serial ( |
||
| const value = result.pkg.exports[key]; | ||
| const k = | ||
| extname(value.default) === ".js" && key !== "." | ||
| ? `${key}.js` | ||
| : key; | ||
|
|
||
| mappedExports[k] = value; | ||
| } | ||
|
|
||
| for (const key in result.pkg.typesVersions["*"]) { | ||
| mappedTypes[`${key}.js`] = result.pkg.typesVersions["*"][key]; | ||
| } | ||
|
|
||
| result.pkg.exports = mappedExports; | ||
| result.pkg.typesVersions["*"] = mappedTypes; | ||
|
|
||
| logger(`extensions preserved`); | ||
| } | ||
|
|
||
| if (options.pkg?.src) { | ||
| logger(`${pkg.name} updating...`); | ||
| const format = getJsonFormat(options.pkg?.snap); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| { | ||
| "name": "demo", | ||
| "dependencies": { | ||
| "atomico": "latest" | ||
| }, | ||
| "peerDependencies": { | ||
| "@atomico/react": "*", | ||
| "@atomico/vue": "*" | ||
| }, | ||
| "peerDependenciesMeta": { | ||
| "@atomico/react": { | ||
| "optional": true | ||
| }, | ||
| "@atomico/vue": { | ||
| "optional": true | ||
| } | ||
| }, | ||
| "main": "./tests/module/atomico.js", | ||
| "module": "./tests/module/atomico.js", | ||
| "types": "./tests/module/atomico.d.ts", | ||
| "exports": { | ||
| "./atomico.js": { | ||
| "types": "./tests/module/atomico.d.ts", | ||
| "default": "./tests/module/atomico.js" | ||
| }, | ||
| "./components/a.js": { | ||
| "default": "./tests/module/components/a/a.js" | ||
| }, | ||
| "./components/b.js": { | ||
| "default": "./tests/module/components/b/b.js" | ||
| }, | ||
| "./components/c.js": { | ||
| "types": "./tests/module/components/c/c.d.ts", | ||
| "default": "./tests/module/components/c/c.js" | ||
| }, | ||
| "./react.js": { | ||
| "types": "./tests/extensions-dist/module/react.d.ts", | ||
| "default": "./tests/extensions-dist/module/react.js" | ||
| }, | ||
| "./preact.js": { | ||
| "types": "./tests/extensions-dist/module/preact.d.ts", | ||
| "default": "./tests/extensions-dist/module/preact.js" | ||
| }, | ||
| "./vue.js": { | ||
| "types": "./tests/extensions-dist/module/vue.d.ts", | ||
| "default": "./tests/extensions-dist/module/vue.js" | ||
| }, | ||
| ".": { | ||
| "types": "./tests/module/atomico.d.ts", | ||
| "default": "./tests/module/atomico.js" | ||
| }, | ||
| "./package.json": { | ||
| "default": "./tests/module/package.json" | ||
| } | ||
| }, | ||
| "typesVersions": { | ||
| "*": { | ||
| "atomico.js": [ | ||
| "./tests/module/atomico.d.ts" | ||
| ], | ||
| "components/c.js": [ | ||
| "./tests/module/components/c/c.d.ts" | ||
| ], | ||
| "react.js": [ | ||
| "./tests/extensions-dist/module/react.d.ts" | ||
| ], | ||
| "preact.js": [ | ||
| "./tests/extensions-dist/module/preact.d.ts" | ||
| ], | ||
| "vue.js": [ | ||
| "./tests/extensions-dist/module/vue.d.ts" | ||
| ] | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { MyComponent as _MyComponent } from "demo"; | ||
| import { Component } from "@atomico/react/preact"; | ||
| export const MyComponent: Component<typeof _MyComponent>; | ||
| declare namespace JSX { | ||
| interface IntrinsicElements{ | ||
| "my-component": Component<typeof _MyComponent>; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| "use client"; | ||
| import { MyComponent as _MyComponent } from "demo"; | ||
| import { auto } from "@atomico/react/preact"; | ||
| export const MyComponent = auto(_MyComponent); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { MyComponent as _MyComponent } from "demo"; | ||
| import { Component } from "@atomico/react"; | ||
| export const MyComponent: Component<typeof _MyComponent>; | ||
| declare namespace JSX { | ||
| interface IntrinsicElements{ | ||
| "my-component": Component<typeof _MyComponent>; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| "use client"; | ||
| import { MyComponent as _MyComponent } from "demo"; | ||
| import { auto } from "@atomico/react"; | ||
| export const MyComponent = auto(_MyComponent); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import { MyComponent as _MyComponent } from "demo"; | ||
| import { Component } from "@atomico/vue"; | ||
| export const MyComponent: Component<typeof _MyComponent>; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| "use client"; | ||
| import { MyComponent as _MyComponent } from "demo"; | ||
| import { auto } from "@atomico/vue"; | ||
| export const MyComponent = auto(_MyComponent); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| { | ||
| "name": "demo", | ||
| "dependencies": { | ||
| "atomico": "latest" | ||
| }, | ||
| "peerDependencies": { | ||
| "@atomico/react": "*", | ||
| "@atomico/vue": "*" | ||
| }, | ||
| "peerDependenciesMeta": { | ||
| "@atomico/react": { | ||
| "optional": true | ||
| }, | ||
| "@atomico/vue": { | ||
| "optional": true | ||
| } | ||
| }, | ||
| "main": "./tests/module/atomico.js", | ||
| "module": "./tests/module/atomico.js", | ||
| "types": "./tests/module/atomico.d.ts", | ||
| "exports": { | ||
| "./atomico.js": { | ||
| "types": "./tests/module/atomico.d.ts", | ||
| "default": "./tests/module/atomico.js" | ||
| }, | ||
| "./components/a.js": { | ||
| "default": "./tests/module/components/a/a.js" | ||
| }, | ||
| "./components/b.js": { | ||
| "default": "./tests/module/components/b/b.js" | ||
| }, | ||
| "./components/c.js": { | ||
| "types": "./tests/module/components/c/c.d.ts", | ||
| "default": "./tests/module/components/c/c.js" | ||
| }, | ||
| "./react.js": { | ||
| "types": "./tests/extensions-dist/module/react.d.ts", | ||
| "default": "./tests/extensions-dist/module/react.js" | ||
| }, | ||
| "./preact.js": { | ||
| "types": "./tests/extensions-dist/module/preact.d.ts", | ||
| "default": "./tests/extensions-dist/module/preact.js" | ||
| }, | ||
| "./vue.js": { | ||
| "types": "./tests/extensions-dist/module/vue.d.ts", | ||
| "default": "./tests/extensions-dist/module/vue.js" | ||
| }, | ||
| ".": { | ||
| "types": "./tests/module/atomico.d.ts", | ||
| "default": "./tests/module/atomico.js" | ||
| }, | ||
| "./package.json": { | ||
| "default": "./tests/module/package.json" | ||
| } | ||
| }, | ||
| "typesVersions": { | ||
| "*": { | ||
| "atomico.js": [ | ||
| "./tests/module/atomico.d.ts" | ||
| ], | ||
| "components/c.js": [ | ||
| "./tests/module/components/c/c.d.ts" | ||
| ], | ||
| "react.js": [ | ||
| "./tests/extensions-dist/module/react.d.ts" | ||
| ], | ||
| "preact.js": [ | ||
| "./tests/extensions-dist/module/preact.d.ts" | ||
| ], | ||
| "vue.js": [ | ||
| "./tests/extensions-dist/module/vue.d.ts" | ||
| ] | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { MyComponent as _MyComponent } from "demo"; | ||
| import { Component } from "@atomico/react/preact"; | ||
| export const MyComponent: Component<typeof _MyComponent>; | ||
| declare namespace JSX { | ||
| interface IntrinsicElements{ | ||
| "my-component": Component<typeof _MyComponent>; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| "use client"; | ||
| import { MyComponent as _MyComponent } from "demo"; | ||
| import { auto } from "@atomico/react/preact"; | ||
| export const MyComponent = auto(_MyComponent); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { MyComponent as _MyComponent } from "demo"; | ||
| import { Component } from "@atomico/react"; | ||
| export const MyComponent: Component<typeof _MyComponent>; | ||
| declare namespace JSX { | ||
| interface IntrinsicElements{ | ||
| "my-component": Component<typeof _MyComponent>; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| "use client"; | ||
| import { MyComponent as _MyComponent } from "demo"; | ||
| import { auto } from "@atomico/react"; | ||
| export const MyComponent = auto(_MyComponent); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import { MyComponent as _MyComponent } from "demo"; | ||
| import { Component } from "@atomico/vue"; | ||
| export const MyComponent: Component<typeof _MyComponent>; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| "use client"; | ||
| import { MyComponent as _MyComponent } from "demo"; | ||
| import { auto } from "@atomico/vue"; | ||
| export const MyComponent = auto(_MyComponent); |
Uh oh!
There was an error while loading. Please reload this page.