Skip to content

Commit

Permalink
feat: update apis/tests for new compiler
Browse files Browse the repository at this point in the history
BREAKING CHANGE: api for compile-time tags has changed.
This affects tranformer/node-factory/code-generator tags.

Co-authored-by: Michael Rawlings <mirawlings@ebay.com>
Co-authored-by: Dylan Piercey <dpiercey@ebay.com>
Co-authored-by: Andrew Gliga <agliga@ebay.com>
  • Loading branch information
3 people committed Feb 25, 2020
1 parent c163054 commit ea6736d
Show file tree
Hide file tree
Showing 177 changed files with 679 additions and 1,574 deletions.
76 changes: 48 additions & 28 deletions packages/marko/bin/markoc.js
Expand Up @@ -5,40 +5,23 @@
var fs = require("fs");
var nodePath = require("path");
var cwd = process.cwd();
var resolveFrom = require("resolve-from");
var resolveFrom = require("resolve-from").silent;

// Try to use the Marko compiler installed with the project
var markoCompilerPath;
var markoCompilerPath = resolveFrom(process.cwd(), "marko/compiler");
const markocPkgVersion = require("../package.json").version;

var markoPkgVersion;
try {
var markoPkgPath = resolveFrom(process.cwd(), "marko/package.json");
markoPkgVersion = require(markoPkgPath).version;
} catch (e) {
/* ignore error */
}

try {
markoCompilerPath = resolveFrom(process.cwd(), "marko/compiler");
} catch (e) {
/* ignore error */
}
var markoPkgPath = resolveFrom(process.cwd(), "marko/package.json");
var markoPkgVersion = markoPkgPath && require(markoPkgPath).version;

var markoCompiler;

if (markoCompilerPath) {
markoCompiler = require(markoCompilerPath);
} else {
markoCompiler = require("../compiler");
}
var markoCompiler = markoCompilerPath
? require(markoCompilerPath)
: require("../compiler");

var Minimatch = require("minimatch").Minimatch;

var appModulePath = require("app-module-path");

markoCompiler.defaultOptions.checkUpToDate = false;

var mmOptions = {
matchBase: true,
dot: true,
Expand Down Expand Up @@ -84,7 +67,16 @@ var args = require("argly")
},
"--vdom -V": {
type: "boolean",
description: "VDOM output"
description: "VDOM output (deprecated, prefer --browser)"
},
"--browser -b": {
type: "boolean",
description: "Browser output"
},
"--source-maps -s": {
type: "string",
description:
"Output a sourcemap beside the compiled file. (use --source-maps inline for an inline source map)"
},
"--version -v": {
type: "boolean",
Expand Down Expand Up @@ -132,14 +124,16 @@ var output = "html";

var isForBrowser = false;

if (args.vdom) {
if (args.vdom || args.browser) {
output = "vdom";
isForBrowser = true;
}

var compileOptions = {
output: output,
browser: isForBrowser,
sourceOnly: false,
sourceMaps: args.sourceMaps || false,
compilerType: "markoc",
compilerVersion: markoPkgVersion || markocPkgVersion
};
Expand Down Expand Up @@ -348,7 +342,7 @@ if (args.clean) {

context.beginAsync();

markoCompiler.compileFile(path, compileOptions, function(err, src) {
markoCompiler.compileFile(path, compileOptions, function(err, result) {
if (err) {
failed.push(
'Failed to compile "' +
Expand All @@ -360,8 +354,9 @@ if (args.clean) {
return;
}

var src = result.code;
context.beginAsync();
fs.writeFile(outPath, src, { encoding: "utf8" }, function(err) {
fs.writeFile(outPath, src, "utf8", function(err) {
if (err) {
failed.push(
'Failed to write "' + path + '". Error: ' + (err.stack || err)
Expand All @@ -370,6 +365,31 @@ if (args.clean) {
return;
}

if (result.map) {
fs.writeFile(
outPath + ".map",
JSON.stringify(result.map),
"utf-8",
function(err) {
if (err) {
failed.push(
'Failed to write sourcemap"' +
path +
'". Error: ' +
(err.stack || err)
);
context.endAsync(err);
return;
}

compileCount++;
context.endAsync();
}
);

return;
}

compileCount++;
context.endAsync();
});
Expand Down
41 changes: 7 additions & 34 deletions packages/marko/package.json
@@ -1,59 +1,43 @@
{
"name": "marko",
"version": "4.18.48",
"version": "5.0.0",
"license": "MIT",
"description": "UI Components + streaming, async, high performance, HTML templating for Node.js and the browser.",
"dependencies": {
"app-module-path": "^2.2.0",
"argly": "^1.0.0",
"browser-refresh-client": "^1.0.0",
"camelcase": "^5.0.0",
"char-props": "~0.1.5",
"complain": "^1.6.0",
"deresolve": "^1.1.2",
"escodegen": "^1.8.1",
"esprima": "^4.0.0",
"estraverse": "^4.3.0",
"events-light": "^1.0.0",
"he": "^1.1.0",
"htmljs-parser": "^2.7.1",
"lasso-caching-fs": "^1.0.1",
"lasso-modules-client": "^2.0.4",
"lasso-package-root": "^1.0.1",
"listener-tracker": "^2.0.0",
"minimatch": "^3.0.2",
"property-handlers": "^1.0.0",
"raptor-regexp": "^1.0.0",
"raptor-util": "^3.2.0",
"resolve-from": "^2.0.0",
"resolve-from": "^5.0.0",
"self-closing-tags": "^1.0.1",
"simple-sha1": "^2.1.0",
"strip-json-comments": "^2.0.1",
"warp10": "^2.0.1"
},
"devDependencies": {
"@marko/migrate": "^5.1.0",
"@marko/compiler": "^5.0.0",
"bluebird": "^3.4.7",
"caller-path": "^2.0.0",
"chai": "^3.3.0",
"chai": "^4.2.0",
"diffable-html": "^2.1.0",
"express": "^4.16.1",
"it-fails": "^1.0.0",
"jquery": "^3.1.1",
"it-fails": "^1.0.4",
"jsdom-context-require": "^1.0.1",
"lasso-resolve-from": "^1.2.0",
"marko-widgets": "^7.0.1",
"micromatch": "^3.0.4",
"request": "^2.72.0",
"through": "^2.3.4",
"through2": "^2.0.1"
},
"main": "index.js",
"browser": {
"./compiler.js": "./compiler-browser.marko",
"./components.js": "./components-browser.marko",
"./index.js": "./index-browser.marko",
"./legacy-components.js": "./legacy-components-browser.marko"
"./index.js": "./index-browser.marko"
},
"bin": {
"markoc": "bin/markoc"
Expand All @@ -66,9 +50,6 @@
"type": "git",
"url": "https://github.com/marko-js/marko.git"
},
"publishConfig": {
"registry": "https://registry.npmjs.org/"
},
"author": "Patrick Steele-Idem <pnidem@gmail.com>",
"maintainers": [
"Patrick Steele-Idem <pnidem@gmail.com>",
Expand Down Expand Up @@ -96,22 +77,14 @@
"bin",
"dist",
"docs",
"helpers",
"src",
"browser-refresh.js",
"compiler-browser.marko",
"compiler.js",
"components-browser.marko",
"components.js",
"env.js",
"express.js",
"hot-reload.js",
"index-browser.marko",
"index.js",
"jquery.marko",
"legacy-components-browser.marko",
"legacy-components.js",
"node-require.js",
"ready.marko"
"node-require.js"
]
}
56 changes: 12 additions & 44 deletions packages/marko/src/compiler/config.js
@@ -1,52 +1,11 @@
var config;

/* globals window */
var g = typeof window === "undefined" ? global : window;

function shouldAssumeUpToDate() {
if (process.env.MARKO_CLEAN != null) {
return false;
}

if (process.env.MARKO_ASSUME_UP_TO_DATE != null) {
return true;
}

return false;
}

if (g.__MARKO_CONFIG) {
config = g.__MARKO_CONFIG;
} else {
config = g.__MARKO_CONFIG = {
/**
* If true, then the compiler will check the disk to see if a previously compiled
* template is the same age or newer than the source template. If so, the previously
* compiled template will be loaded. Otherwise, the template will be recompiled
* and saved to disk.
*
* If false, the template will always be recompiled. If `writeToDisk` is false
* then this option will be ignored.
*/
checkUpToDate: process.env.MARKO_CLEAN ? false : true,
/**
* If true (the default) then compiled templates will be written to disk. If false,
* compiled templates will not be written to disk (i.e., no `.marko.js` file will
* be generated)
*/
writeToDisk: true,

/**
* If true, then the compiled template on disk will assumed to be up-to-date if it exists.
*/
assumeUpToDate: shouldAssumeUpToDate(),

/**
* If true, whitespace will be preserved in templates. Defaults to false.
* @type {Boolean}
*/
preserveWhitespace: false,

// The default output mode for compiled templates
output: "html",

Expand All @@ -63,10 +22,19 @@ if (g.__MARKO_CONFIG) {
ignoreUnrecognizedTags: false,

/**
* Controls whether or not a key should be assigned to all HTML
* and custom tags at compile-time. The default is `true`
* Whether source maps should be output with the compiled templates.
* When `true` a `map` property will be available on the compile result.
* When `"inline"` the sourcemap will be inlined as a comment in the output code.
* When `"both"` both of the above will be used.
*/
sourceMaps: false,

/**
* This option inlines all of the meta data in the template.
* You can also access this metadata via `compile(...).meta`.
* This API is sticking around for compatibility purposes.
*/
autoKeyEnabled: true
meta: true
};

if (process.env.MARKO_CONFIG) {
Expand Down

0 comments on commit ea6736d

Please sign in to comment.