@atlassian/atlassian-soy-loader
Advanced tools
Comparing version 2.1.1 to 2.2.0
const esprima = require('esprima'); | ||
const esquery = require('esquery'); | ||
module.exports = (soyJs, globalObj) => { | ||
function exposeNamespaceGlobally(namespace, dontExposeGlobally) { | ||
if (dontExposeGlobally) { | ||
return ''; | ||
} | ||
const target = `window.${namespace}`; | ||
return `// Exposed to window by expose-soy | ||
${target} = ${target} || {};` | ||
} | ||
module.exports = (soyJs, dontExposeGlobally) => { | ||
const ast = esprima.parse(soyJs); | ||
// assume the first variable declared is the top level of the namespace | ||
const namespace = esquery(ast, 'VariableDeclarator')[0].id.name; | ||
const target = `${globalObj}.${namespace}`; | ||
const exposedSoyJs = `// Exposed to ${globalObj} by expose-soy | ||
if (typeof ${target} == 'undefined') { ${target} = {}; } | ||
${namespace} = ${target}; | ||
return ` | ||
${exposeNamespaceGlobally(namespace, dontExposeGlobally)} | ||
${soyJs} | ||
module.exports = ${namespace}; | ||
`; | ||
return exposedSoyJs; | ||
}; |
30
index.js
@@ -48,16 +48,16 @@ const fs = require('fs'); | ||
if (queue.qs.functions) { | ||
args.push('--functions', `file:///${toJavaPath(queue.qs.functions, cwd)}`); | ||
if (queue.options.functions) { | ||
args.push('--functions', `file:///${toJavaPath(queue.options.functions, cwd)}`); | ||
} | ||
if (queue.qs.i18n) { | ||
args.push('--i18n', queue.qs.i18n); | ||
if (queue.options.i18n) { | ||
args.push('--i18n', queue.options.i18n); | ||
} | ||
if (queue.qs.i18nBaseDir) { | ||
args.push('--i18n-basedi', queue.qs.i18nBaseDir); | ||
if (queue.options.i18nBaseDir) { | ||
args.push('--i18n-basedi', queue.options.i18nBaseDir); | ||
} | ||
if (queue.qs.data) { | ||
args.push('--data', queue.qs.data); | ||
if (queue.options.data) { | ||
args.push('--data', queue.options.data); | ||
} | ||
@@ -106,3 +106,3 @@ | ||
const exposed = exposeSoy(compiled, 'window'); | ||
const exposed = exposeSoy(compiled, queue.options.dontExpose); | ||
@@ -123,6 +123,10 @@ item.callback(null, exposed); | ||
if (!has(queues, this.query)) { | ||
queues[this.query] = { | ||
const options = loaderUtils.getOptions(this); | ||
// this is not entirely correct e.g. if there was function being passed | ||
const optionsString = JSON.stringify(options); | ||
if (!has(queues, optionsString)) { | ||
queues[optionsString] = { | ||
debug: this.debug, | ||
qs: this.query && loaderUtils.parseQuery(this.query), | ||
options: options, | ||
items: [] | ||
@@ -132,3 +136,3 @@ }; | ||
const queue = queues[this.query]; | ||
const queue = queues[optionsString]; | ||
@@ -135,0 +139,0 @@ queue.items.push({ |
{ | ||
"name": "@atlassian/atlassian-soy-loader", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"description": "Soy loader for webpack using the Atlassian Soy CLI compiler", | ||
@@ -37,4 +37,3 @@ "main": "index.js", | ||
"@atlassian/eslint-config-atlassian-fecq": "^2.0.3", | ||
"eslint": "^4.10.0", | ||
"loader-utils": "^1.1.0" | ||
"eslint": "^4.10.0" | ||
}, | ||
@@ -46,3 +45,4 @@ "dependencies": { | ||
"lodash": "^4.17.4", | ||
"tmp": "0.0.33" | ||
"tmp": "0.0.33", | ||
"loader-utils": "^1.1.0" | ||
}, | ||
@@ -49,0 +49,0 @@ "peerDependencies": { |
@@ -40,2 +40,3 @@ Atlassian Soy Loader | ||
i18nBaseDir: '/foo/bar/path' // optional, base directory for i18n properties file | ||
dontExpose: true // default: false - indicate if the generated namespace should be exposed to the window or not. | ||
} | ||
@@ -42,0 +43,0 @@ } |
12474
2
128
83
7
+ Addedloader-utils@^1.1.0