Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Bundleless mode ouput files outside of the specified entries #498

Closed
patricklafrance opened this issue Nov 29, 2024 · 8 comments
Closed
Labels
🐞 bug Something isn't working

Comments

@patricklafrance
Copy link

patricklafrance commented Nov 29, 2024

Version

System:
    OS: Windows 11 10.0.22631
    CPU: (20) x64 13th Gen Intel(R) Core(TM) i7-13700H
    Memory: 9.07 GB / 31.62 GB
  Browsers:
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.22621.3527

Details

When Rslib is configured to ouput bundleless files, it also generate dts files for folders that are outside of my entry point (the tests folder and the tooling configuration files like jest.config.ts). Is it a known issue or i'm I missing a configuration?

I am using version 0.1.0 and my config is:

export default defineConfig({
    lib: [{
        format: "esm",
        syntax: "esnext",
        bundle: false,
        dts: true
    }],
    source: {
        entry: {
            index: "./src/index.ts"
        }
    },
    output: {
        target: "web",
        distPath: {
            root: "./dist"
        },
        cleanDistPath: true,
        minify: false
    }
});

I also tried without success:

export default defineConfig({
    lib: [{
        format: "esm",
        syntax: "esnext",
        bundle: false,
        dts: true
    }],
    source: {
        entry: {
            index: "./src/**"
        }
    },
    output: {
        target: "web",
        distPath: {
            root: "./dist"
        },
        cleanDistPath: true,
        minify: false
    }
});

Image

Reproduce Steps

  • rslib build
@patricklafrance patricklafrance added the 🐞 bug Something isn't working label Nov 29, 2024
@Timeless0911
Copy link
Contributor

Can you show your tsconfig.json, I think maybe the rootDir is not set to ./src.

@patricklafrance
Copy link
Author

patricklafrance commented Nov 30, 2024

{
    "$schema": "https://json.schemastore.org/tsconfig",
    "compilerOptions": {
        "allowImportingTsExtensions": true,
        "moduleResolution": "NodeNext",
        "module": "NodeNext",
        "target": "ESNext",
        "lib": ["ESNext"],

        "isolatedModules": true,
        "allowSyntheticDefaultImports": true,
        "resolveJsonModule": true,

        "strict": true,

        "allowJs": true,
        "checkJs": false,

        "esModuleInterop": true,
        "skipLibCheck": true,
        "forceConsistentCasingInFileNames": true,

        "noEmit": true,
        "sourceMap": false
    },
    "exclude": ["dist", "node_modules"]
}

I tried adding:

"rootDir": "src"

But then I get the following error:

start   Generating DTS... (esm)
error   Failed to emit declaration files. (esm)
error  XYZ/wl-squide/packages/core/tsconfig.json - error TS6059: File 'XYZ/wl-squide/packages/core/jest.config.ts' is not under 'rootDir' 'XYZ/wl-squide/packages/core/src'. 'rootDir' is expected to contain all source files.
  The file is in the program because:
    Root file specified for compilation
  File is ECMAScript module because 'XYZ/wl-squide/packages/core/package.json' has field "type" with value "module"

Shouldn't the source.entry option of my Rslib config file be enough though?

@Timeless0911
Copy link
Contributor

The dts generation is equivalent to npx tsc command. And the above error shows you should configure corresponding include field in tsconfig.json·

You can create a new tsconfig.build.json to do that and remember to set source.tsconfigPath to tsconfig.build.json in your rslib.config.ts.

@patricklafrance
Copy link
Author

patricklafrance commented Nov 30, 2024

Thanks @Timeless0911, indeed it fixed the issue thank you 🙏🏻

Could somehow Rslib abstract the need for a custom tsconfig.build.json file by forwarding CLI arguments based on source.entry to the underlying tool used to generated the DTS?

@patricklafrance
Copy link
Author

patricklafrance commented Nov 30, 2024

Oh wait, now the DTS files are fine but there's no source code anymore

Image

All I got is an index.js referencing files that doesn't exist.

export * from "./shared/assertions.js";
export * from "./logging/consoleLogger.js";
export * from "./logging/logger.js";
export * from "./runtime/runtime.js";
export * from "./runtime/RuntimeContext.js";
export * from "./runtime/RuntimeLogger.js";
export * from "./runtime/useEventBus.js";
export * from "./runtime/useLogger.js";
export * from "./runtime/usePlugin.js";
export * from "./runtime/useRuntimeMode.js";
export * from "./messaging/eventBus.js";
export * from "./messaging/useEventBusDispatcher.js";
export * from "./messaging/useEventBusListener.js";
export * from "./registration/mergeDeferredRegistrations.js";
export * from "./registration/moduleRegistry.js";
export * from "./registration/registerLocalModules.js";
export * from "./registration/registerModule.js";
export * from "./plugins/plugin.js";

;// CONCATENATED MODULE: ./src/index.ts?__rslib_entry__

I'll extract a reproduction from by repository.

@patricklafrance
Copy link
Author

patricklafrance commented Nov 30, 2024

@Timeless0911
Copy link
Contributor

Could somehow Rslib abstract the need for a custom tsconfig.build.json file by forwarding CLI arguments based on source.entry to the underlying tool used to generated the DTS?

The Typescript Compiler need tsconfig.json to generate outputs, I think we can add some checks to warn users that they should configure tsconfig.json well, but it is a huge work and we hope to achieve this in the future.

the DTS files are fine but there's no source code anymore

You use bundle: false in config file which means you want a bundleless output, but you only specified source.entry to ./src/index.ts, which means Rslib will only transform ./src/index.ts to index.js.

The correct config is

source: {
    entry: {
-        index: "./src/index.ts"
+        index: "./src/**"
    },
},

see https://lib.rsbuild.dev/config/lib/bundle#bundle-false for details

@patricklafrance
Copy link
Author

Ah you're right! It works as expected now, thank you for your help 🙏🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants