Skip to content

Commit

Permalink
feat: expose api to get runtime entry files for translator (#1687)
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Apr 21, 2021
1 parent eec8665 commit fad9159
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/compiler/index.d.ts
Expand Up @@ -82,6 +82,8 @@ export function compileFileSync(
config?: Config
): CompileResult;

export function getRuntimeEntryFiles(output: string, translator?: string | undefined): string[];

export namespace taglib {
export function excludeDir(dirname: string): void;
export function excludePackage(packageName: string): void;
Expand Down
11 changes: 11 additions & 0 deletions packages/compiler/src/index.js
Expand Up @@ -3,6 +3,8 @@ import * as babel from "@babel/core";
import corePlugin from "./babel-plugin";
import defaultConfig from "./config";
import * as taglib from "./taglib";
import shouldOptimize from "./util/should-optimize";
import tryLoadTranslator from "./util/try-load-translator";
export { taglib };

let globalConfig = { ...defaultConfig };
Expand Down Expand Up @@ -41,6 +43,15 @@ export function compileFileSync(filename, config) {
return compileSync(src, filename, config);
}

export function getRuntimeEntryFiles(output, requestedTranslator) {
const translator = tryLoadTranslator(requestedTranslator);
if (translator && translator.getRuntimeEntryFiles) {
return translator.getRuntimeEntryFiles(output, shouldOptimize());
}

return [];
}

function loadBabelConfig(filename, config) {
const markoConfig = { ...globalConfig, ...config, babelConfig: undefined };
const requiredPlugins = [[corePlugin, markoConfig]];
Expand Down
49 changes: 49 additions & 0 deletions packages/translator-default/src/index.js
Expand Up @@ -430,6 +430,55 @@ export const translate = {
}
};

export function getRuntimeEntryFiles(output, optimize) {
const base = `marko/${optimize ? "dist" : "src"}/`;

return [
`${base}runtime/components`,
`${base}runtime/components/defineComponent`,
`${base}runtime/components/renderer`,
`${base}runtime/components/registry`,
`${base}runtime/components/attach-detach`,
`${base}runtime/helpers/assign`,
`${base}runtime/helpers/class-value`,
`${base}runtime/helpers/dynamic-tag`,
`${base}runtime/helpers/load-nested-tag`,
`${base}runtime/helpers/merge`,
`${base}runtime/helpers/render-tag`,
`${base}runtime/helpers/style-value`,
`${base}runtime/helpers/to-string`,
`${base}core-tags/components/preserve-tag`,
`${base}core-tags/components/init-components-tag`,
`${base}core-tags/components/preferred-script-location-tag`,
`${base}core-tags/core/__flush_here_and_after__`,
`${base}core-tags/core/await/renderer`,
`${base}core-tags/core/await/reorderer-renderer`,
...(output === "html"
? [
`${base}runtime/html`,
`${base}runtime/html/helpers/attr`,
`${base}runtime/html/helpers/attrs`,
`${base}runtime/html/helpers/class-attr`,
`${base}runtime/html/helpers/data-marko`,
`${base}runtime/html/helpers/escape-quotes`,
`${base}runtime/html/helpers/escape-script-placeholder`,
`${base}runtime/html/helpers/escape-style-placeholder`,
`${base}runtime/html/helpers/escape-xml`,
`${base}runtime/html/helpers/merge-attrs`,
`${base}runtime/html/helpers/props-script`,
`${base}runtime/html/helpers/style-attr`
]
: [
`${base}runtime/vdom`,
`${base}runtime/vdom/helpers/attrs`,
`${base}runtime/vdom/helpers/const`,
`${base}runtime/vdom/helpers/v-element`,
`${base}runtime/vdom/helpers/v-text`,
`${base}runtime/vdom/preserve-attrs`
])
];
}

function isRenderContent(path) {
const { node } = path;
return t.MARKO_TYPES.includes(node.type) && !node.static;
Expand Down

0 comments on commit fad9159

Please sign in to comment.