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

ColorUsageType is not exported as usable enum #528

Merged
merged 3 commits into from
Oct 23, 2024

Conversation

pietervp
Copy link
Member

@pietervp pietervp commented Oct 22, 2024

This fixes the export for ColorUsageType, and other enum or class types that are exported as TypeAlias.
`
Example where it goes wrong:

(async () => {
    // Fetch all frames to find the ID of the frame named 'InventoryBarcode'
    const framesResponse = await window.SDK.frame.getAll();
    const frames = framesResponse.parsedData;
    // Find the frame with name 'InventoryBarcode', case insensitive
    const inventoryBarcodeFrame = frames.find(frame => frame.name.toLowerCase() === 'inventorybarcode');
    if (!inventoryBarcodeFrame) {
        throw new Error("Frame 'InventoryBarcode' not found");
    }
 
    const frameId = inventoryBarcodeFrame.id;
 
    // Define the custom hex color
    const backgroundColor: ColorUsage = {
        color: {
            value: '#FF5733',
            type: ColorType.hex
        },
        type: ColorUsageType.local
    };
 
    // Set the background color of the 'InventoryBarcode' frame
    await window.SDK.barcode.setBackgroundColor(frameId, backgroundColor);
})();

throws errors like

'ColorUsageType' cannot be used as a value because it was exported using 'export type'.

For reference, this is the script used to find all offenders:

import { Project, SyntaxKind } from "ts-morph";

const project = new Project({
  tsConfigFilePath: "./clones/studio-sdk/packages/sdk/tsconfig.json",
});

const sourceFile = project.getSourceFileOrThrow("index.ts");
const allDeclarations = sourceFile.getExportedDeclarations();

sourceFile.getDescendantsOfKind(SyntaxKind.ExportDeclaration).forEach((e) => {
  const exportListIsTypeOnly = e.isTypeOnly();
  e.getNamedExports().forEach((n) => {
    // used to resolve the name of the export in the declarations map
    const exportName = n.getAliasNode()?.getText() ?? n.getName();
    const exportIsTypeOnly = n.isTypeOnly();

    allDeclarations.get(exportName)?.forEach((d) => {
      // type only exports must be type aliases
      if (d.getKind() !== SyntaxKind.TypeAliasDeclaration && (exportListIsTypeOnly || exportIsTypeOnly)) {
        console.error(`'${n.getText()}' at ${n.compilerNode.getFullStart()}, ${n.compilerNode.getEnd()} is type only but is not a type alias (${d.getKindName()})`);
      }
    });
  });
});

This fixes the export for ColorUsageType

Example where it goes wrong:

```ts
(async () => {
    // Fetch all frames to find the ID of the frame named 'InventoryBarcode'
    const framesResponse = await window.SDK.frame.getAll();
    const frames = framesResponse.parsedData;
    // Find the frame with name 'InventoryBarcode', case insensitive
    const inventoryBarcodeFrame = frames.find(frame => frame.name.toLowerCase() === 'inventorybarcode');
    if (!inventoryBarcodeFrame) {
        throw new Error("Frame 'InventoryBarcode' not found");
    }
 
    const frameId = inventoryBarcodeFrame.id;
 
    // Define the custom hex color
    const backgroundColor: ColorUsage = {
        color: {
            value: '#FF5733',
            type: ColorType.hex
        },
        type: ColorUsageType.local
    };
 
    // Set the background color of the 'InventoryBarcode' frame
    await window.SDK.barcode.setBackgroundColor(frameId, backgroundColor);
})();
```

throws errors like

`'ColorUsageType' cannot be used as a value because it was exported using 'export type'.`
Copy link
Contributor

Coverage Report

Coverage report can be checked at https://stgrafxstudiodevpublic.blob.core.windows.net/sdk/coverage/528/coverage.html

Use PR sdk package

Tarball can be downloaded from https://stgrafxstudiodevpublic.blob.core.windows.net/sdk/dev-packages/528/studio-sdk.tgz

To use in local project, change package.json to use local tarball

"dependencies": {
    "@chili-publish/studio-sdk": "https://stgrafxstudiodevpublic.blob.core.windows.net/sdk/dev-packages/528/studio-sdk.tgz"
}

Copy link
Contributor

github-actions bot commented Oct 22, 2024

Unit Test Results

    1 files    36 suites   39s ⏱️
389 tests 389 ✔️ 0 💤 0
400 runs  400 ✔️ 0 💤 0

Results for commit bd90c11.

♻️ This comment has been updated with latest results.

psamusev
psamusev previously approved these changes Oct 22, 2024
@brapoprod brapoprod merged commit 49a3c5e into main Oct 23, 2024
6 checks passed
@brapoprod brapoprod deleted the bugfix/properly-export-colorUsageType branch October 23, 2024 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants