Skip to content

Commit

Permalink
fix: typescript support for marko 4 (#2041)
Browse files Browse the repository at this point in the history
  • Loading branch information
agliga committed Dec 28, 2023
1 parent 616bae2 commit 5c3ac86
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 35 deletions.
3 changes: 1 addition & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
},
"dependencies": {
"@marko-tags/subscribe": "^0.5.1",
"@floating-ui/core": "^1.5.2",
"@floating-ui/dom": "^1.5.2",
"makeup-active-descendant": "0.6.1",
"makeup-expander": "~0.10.1",
"makeup-floating-label": "~0.3.2",
Expand Down
20 changes: 11 additions & 9 deletions scripts/generate-cdn.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import * as https from "https"; // or 'https' for https:// URLs
import { fileURLToPath } from "url";
import * as fs from "fs";
import * as path from "path";
import rimraf from "rimraf";
import * as rimraf from "rimraf";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const rootDir = path.join(__dirname, "..");
const versionPath = "src/common/cdn/versions.json";
const versionPath = "src/common/cdn/versions.ts";

const cdnConfig = {
shaka: {
Expand All @@ -37,9 +37,11 @@ function updateVersionFile(version) {
{
"//": "This is a generated file. Run generateCDN script file to update",
},
version
version,
);
const newVersion = JSON.stringify(versionObject);
const newVersion = `export const versions = ${JSON.stringify(
versionObject,
)};`;
fs.writeFileSync(versionFile, newVersion);
}

Expand Down Expand Up @@ -70,29 +72,29 @@ async function shakaGenerator({ version, cdnVersionPath }) {
await download(getShakaCSSUrl(version), cdnVersionPath, "controls.css");
// Remove define
execSync(
`sed -i '' -e 's/typeof define=="function"/typeof define=="w"/' ${cdnVersionPath}/shaka-player.ui.js`
`sed -i '' -e 's/typeof define=="function"/typeof define=="w"/' ${cdnVersionPath}/shaka-player.ui.js`,
);
}

async function threeDPlayerGenerator({ cdnVersionPath }) {
await fs.promises.cp(
`${rootDir}/node_modules/@google/model-viewer/dist/model-viewer.min.js`,
`${cdnVersionPath}/model-viewer.min.js`
`${cdnVersionPath}/model-viewer.min.js`,
);
}

async function highchartsGenerator({ cdnVersionPath }) {
await fs.promises.cp(
`${rootDir}/node_modules/highcharts/highcharts.js`,
`${cdnVersionPath}/highcharts.js`
`${cdnVersionPath}/highcharts.js`,
);
await fs.promises.cp(
`${rootDir}/node_modules/highcharts/modules/accessibility.js`,
`${cdnVersionPath}/accessibility.js`
`${cdnVersionPath}/accessibility.js`,
);
await fs.promises.cp(
`${rootDir}/node_modules/highcharts/modules/pattern-fill.js`,
`${cdnVersionPath}/pattern-fill.js`
`${cdnVersionPath}/pattern-fill.js`,
);
}

Expand Down
5 changes: 4 additions & 1 deletion scripts/prepublish.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ const componentInputDir = path.join(rootDir, "src/components");

// run typescript compiler
execSync("mtc");
execSync("babel --env-name prod dist --out-dir dist --copy-files");
// Rename all exports.default to module.exports
execSync(
"find dist -type f -name 'component*.js' | xargs sed -i '' 's/exports.default =/module.exports =/g'",
);

// create top level browser.json files to map to nested ones
fs.readdirSync(componentInputDir)
Expand Down
2 changes: 1 addition & 1 deletion src/common/cdn/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { loader } from "../loader";
import versions from "./versions.json";
import { versions } from "./versions";
const MAX_RETRIES = 3;

interface CDNLoaderConfig {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
export const versions = {
"//": "This is a generated file. Run generateCDN script file to update",
"shaka": "4.3.2",
"highcharts": "10.2.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import type { AttrClass } from "marko/tags-html";
export const typeRoles = {
tourtip: "region",
tooltip: "tooltip",
infotip: "tooltip",
} as const;
import {typeRoles} from './constants'

interface TooltipOverlayInput {
toJSON?: any;
Expand Down
5 changes: 5 additions & 0 deletions src/components/components/ebay-tooltip-overlay/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const typeRoles = {
tourtip: "region",
tooltip: "tooltip",
infotip: "tooltip",
} as const;
2 changes: 1 addition & 1 deletion src/components/components/ebay-tooltip-overlay/index.marko
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { processHtmlAttributes } from "../../../common/html-attributes";
import { typeRoles } from "./component-browser";
import { typeRoles } from "./constants";

static function noop() {}

Expand Down
3 changes: 1 addition & 2 deletions src/components/ebay-button/component-browser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as eventUtils from "../../common/event-utils";

export const validSizes = ["large", "small"] as const;
import { validSizes } from "./constants";

export interface ButtonEvent<T extends Event> {
originalEvent: T;
Expand Down
1 change: 1 addition & 0 deletions src/components/ebay-button/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const validSizes = ["large", "small"] as const;
2 changes: 1 addition & 1 deletion src/components/ebay-button/index.marko
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { processHtmlAttributes } from "../../common/html-attributes"
import { validSizes } from "./component-browser"
import {validSizes} from "./constants"

static function toJSON(this: any) {
return {
Expand Down
1 change: 0 additions & 1 deletion src/components/ebay-carousel/index.marko
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ $ var config = data.config;
class=item.class
style=item.style
aria-hidden=!item.fullyVisible && 'true'
no-update-body-if=!!config.preserveItems
>
<${item.renderBody}/>
</li>
Expand Down
8 changes: 4 additions & 4 deletions src/components/ebay-filter-menu-button/index.marko
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ $ const {
formAction,
formMethod,
items,
type,
type: inputType,
...htmlInput
} = input;

Expand All @@ -40,7 +40,7 @@ $ const {
<ebay-filter-menu
classPrefix="filter-menu-button"
variant=variant
type=type
type=inputType
formName=formName
formAction=formAction
formMethod=formMethod
Expand All @@ -58,10 +58,10 @@ $ const {
${footerText}
</@footer>
</if>
<else-if(footer)>
<else><if(footer)>
<@footer ...footer a11yFooterText=(a11yFooterText || footer.a11yFooterText)>
<${footer.renderBody}/>
</@footer>
</else-if>
</if></else>
</ebay-filter-menu>
</span>
2 changes: 1 addition & 1 deletion src/components/ebay-listbox/index.marko
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ $ const {
...htmlInput
} = input;

$ var selectedOption = (options as Option[])?.[state.selectedIndex];
$ var selectedOption = (options as Option[])[state.selectedIndex];

<div
...processHtmlAttributes(htmlInput)
Expand Down
1 change: 0 additions & 1 deletion src/components/ebay-menu-button/style.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
import "@ebay/skin/menu-button";
import "./ebay-menu-button.css";
8 changes: 4 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"incremental": true,
"lib": ["dom", "ESNext"],
"module": "ESNext",
"moduleResolution": "bundler",
"lib": ["dom"],
"module": "commonjs",
"moduleResolution": "node",
"noImplicitOverride": true,
"noUnusedLocals": true,
"outDir": "dist",
"resolveJsonModule": true,
"rootDir": "src",
"skipLibCheck": true,
"strict": true,
"target": "ES6",
"target": "ES2015",
"tsBuildInfoFile": "dist/tsconfig.tsbuildinfo"
}
}

0 comments on commit 5c3ac86

Please sign in to comment.