FluidFramework icon indicating copy to clipboard operation
FluidFramework copied to clipboard

refactor(type-tests): Updated type tests to check for and use alpha packages

Open WayneFerrao opened this issue 1 year ago • 6 comments

AB#6418

Description

This PR updates our type tests to check for alpha. Our public APIs are exposed through the root path of the package, while 'alpha' APIs, which are used by internal partners, are exposed through an /alpha path which we need our type tests to look at. This PR refactors the type test script into separate functions and adds logic to check if a package has /alpha and if it doesn't to fall back to using standard import; index.d.ts.

This PR also adds unit tests for the abstracted functions.

Note

Type trimming hasn't been enabled yet.

WayneFerrao avatar Dec 07 '23 20:12 WayneFerrao

Its practical to read the jsdoc tags and use them for things. I have a PR with such changes in https://github.com/microsoft/FluidFramework/pull/19224 .

I think the approach taken here to use the rollups seems like a good even if we have access to the tags, but if there are issues using the rollups, or you want access to the release tags for some other reason, my PR has what you need to get them.

CraigMacomber avatar Jan 12 '24 00:01 CraigMacomber

@WayneFerrao Any idea when you'll be able to merge this?

tylerbutler avatar Mar 25 '24 19:03 tylerbutler

@WayneFerrao Any idea when you'll be able to merge this?

Sorry for the delay on this. I had deprioritized this PR to focus on Devtools tasks/bugs. This is nearly complete, I just need to finish the unit and integration tests.

WayneFerrao avatar Mar 29 '24 17:03 WayneFerrao

I tested this out on my RC 3 typetest update PR, and there's an exception thrown immediately. I used the sequence package for testing. Just go to that directory and run the type-test-generator:

$ node D:\code\fluid-bt\build-tools\packages\build-tools\bin\fluid-type-test-generator 
D:\code\Fluid-bt\build-tools\node_modules\.pnpm\[email protected]\node_modules\ts-morph\dist\ts-morph.js:20557
                throw new common.errors.InvalidOperationError(`Could not find source file in project at the provided path: ${errorFileNameOrPath}`);
                ^

InvalidOperationError: Could not find source file in project at the provided path: D:/code/FluidFramework/packages/dds/sequence/@fluidframework/sequence-previous-alpha.d.ts
    at Project.getSourceFileOrThrow (D:\code\Fluid-bt\build-tools\node_modules\.pnpm\[email protected]\node_modules\ts-morph\dist\ts-morph.js:20557:23)
    at initializeProjectsAndLoadFiles (D:\code\fluid-bt\build-tools\packages\build-tools\dist\type-test-generator\typeTestUtils.js:140:32)
    at Object.<anonymous> (D:\code\fluid-bt\build-tools\packages\build-tools\dist\type-test-generator\main.js:34:90)
    at Module._compile (node:internal/modules/cjs/loader:1364:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1422:10)
    at Module.load (node:internal/modules/cjs/loader:1203:32)
    at Module._load (node:internal/modules/cjs/loader:1019:12)
    at Module.require (node:internal/modules/cjs/loader:1231:19)
    at require (node:internal/modules/helpers:177:18)
    at Object.<anonymous> (D:\code\fluid-bt\build-tools\packages\build-tools\bin\fluid-type-test-generator:2:1)

tylerbutler avatar Apr 22 '24 17:04 tylerbutler

@jason-ha @WayneFerrao After looking at this PR in more detail and testing it, I ended up opening a new PR, https://github.com/microsoft/FluidFramework/pull/20803, which is built on top of this. Importantly, it uses resolve.exports to find paths to types, and it uses a new flub command as the frontend instead of fluid-type-test-generator's main function. More details are in the PR description.

tylerbutler avatar Apr 23 '24 23:04 tylerbutler

@jason-ha @WayneFerrao After looking at this PR in more detail and testing it, I ended up opening a new PR, #20803, which is built on top of this. Importantly, it uses resolve.exports to find paths to types, and it uses a new flub command as the frontend instead of fluid-type-test-generator's main function. More details are in the PR description.

I left comments there. That is better, but I do still think, as I commented in here, that we should work from the actual exports and not try peeking in and decoding file paths. Only thing worth looking up specially could be the previous package.json's exports listing (assuming we don't want to add ./package.json to exports as some do to make it accessible).

jason-ha avatar Apr 28 '24 07:04 jason-ha

Work moved to and completed in this PR https://github.com/microsoft/FluidFramework/pull/20803

WayneFerrao avatar May 08 '24 18:05 WayneFerrao