-
Notifications
You must be signed in to change notification settings - Fork 536
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
build(client-tree): exports with ESM as primary #19141
build(client-tree): exports with ESM as primary #19141
Conversation
- exports not specified - API extractor for CJS does not work properly
remove unused build:gen-version
make sure cjs rollup uses cjs config override moduleResolution for esm as api-extractor doesn't handle node16 robustly. It will generate with imports to invalid paths.
use Bundler for moduleResolution with ESNext
echo quote emit syntax is different per shell. Instead copy a file.
Add comments for module/moduleResolution settings and make moduleResolution explicit. Also inject package.json for ESM for symmetry.
6870b1a
to
0bcd137
Compare
I dug up the comment that describes some drawbacks to this approach: microsoft/TypeScript#54593 (comment) I don't think this is an immediate blocker for us, but it makes me think this is a design that we'll still have to revisit later. Maybe just something we note in the readme or dev notes and revisit when it becomes a practical blocker. |
I was emitting I am hoping that we are really working toward an ESM only future and would then be able to drop secondary CJS build. If we can't before there is issue with Those seem more tractable than using tools that we can't rely on as much as tsc. Last weekend I was playing around with addition to tsc-multi to hook package.json reads and override type. Using it for just that feature seems safe to me. (No extension or file rewrites.) |
"compiler": { | ||
"tsconfigFilePath": "<projectFolder>/tsconfig.cjs.json" | ||
}, | ||
"apiReport": { | ||
"enabled": false | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these be defined in the base config? If not, add some comments to this file with some explanation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure what the question is.
- Should tsconfigFilePath be set in build-common/api-extractor-base.cjs*.json? No each package may have its own tsconfig setup at the moment.
- Should apiReport be disabled in build-common/api-extractor-base.json? I think it should probably be off in there. The -base.*.primary.json files however would want it on. This config wants the extension neutral (.ts) settings from .primary.json but not the apiReport.
"compiler": { | ||
"overrideTsconfig": { | ||
"$schema": "http://json.schemastore.org/tsconfig", | ||
"extends": "./tsconfig.esnext.json", | ||
"compilerOptions": { | ||
"module": "esnext", | ||
"moduleResolution": "Bundler" | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question here.
@@ -1,4 +1,15 @@ | |||
{ | |||
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", | |||
"extends": "../../../common/build/build-common/api-extractor-base.json" | |||
"extends": "../../../common/build/build-common/api-extractor-base.json", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this extend from api-extractor-base while the others use different bases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed? Seems like the package.json scripts explicitly pass a config file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Everything eventually extends from api-extractor-base. The other build-common files extend api-extractor-base, set entry point, set rollup files, and if not primary disable apiReport.
build:docs
andci:build:docs
use this file implicitly.
@@ -11,18 +11,42 @@ | |||
"license": "MIT", | |||
"author": "Microsoft and contributors", | |||
"sideEffects": false, | |||
"type": "module", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this a bit dangerous?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know that this is dangerous. Why might it be dangerous?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I haven't requested the tsc-multi feature that I think it needs. Without tsc seeing "type": "module" it doesn't go into full ESM mode. This is a must for now to ensure proper ESM transpilation.)
@@ -46,7 +70,7 @@ | |||
"test:snapshots:regen": "npm run test:mocha -- --snapshot", | |||
"test:stress": "cross-env FUZZ_TEST_COUNT=20 FUZZ_STRESS_RUN=true mocha --ignore \"dist/test/memory/**/*\" --recursive \"dist/test/**/*.spec.js\" -r @fluidframework/mocha-test-setup", | |||
"ts2esm": "ts2esm ./tsconfig.json ./src/test/tsconfig.json", | |||
"tsc": "tsc", | |||
"tsc": "tsc --project ./tsconfig.cjs.json && copyfiles -f ../../../common/build/build-common/src/cjs/package.json ./dist", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine for now since fluid-build understands tsc and copyfiles and should decompose this into two dependent tasks (one for tsc and the other for copyfiles). However, longer-term I think the pattern we should use is to have explicit separate tasks for the copying and make those dependencies explicit in the fluid-build config as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did enjoy fluid-build being smart about this. I am not sure the long-term desired breakup. I guess tsc
would kick off the two tasks b/c we want to keep the main build command simple and common. So, we have tsc that does tsc:transpile and tsc:setcjs later?
Ah timing. Looks like some non-public use of tree snuck in. exports will need adjusted (if not removed). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just looked at the Devtools change in detail. Can't vouch for the rest :)
import type { ISharedTree } from "@fluidframework/tree/internal"; | ||
import { SharedTree, encodeTreeSchema } from "@fluidframework/tree/internal"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just surprised to see these are all internal now. Are we sure not even ISharedTree should be public?
- Configure full ESM build and declaration for tree - Set exports (only "public" and `internal` as there are no others) - "@internal" uses of tree updated to import "/internal" - Build CommonJS secondarily with injected CommonJS package.json at build A module package.json is also injected into ESM build for symmetry. ESM api-extractor tsconfig is overwritten to use `Bundler` resolution as `Node16` does not appear to be robustly handled.
internal
as there are no others)A module package.json is also injected into ESM build for symmetry.
ESM api-extractor tsconfig is overwritten to use
Bundler
resolution asNode16
does not appear to be robustly handled.