Comparing version 0.4.2 to 0.5.0
@@ -1,2 +0,2 @@ | ||
var e=require("path"),r=require("fs"),t=require("babel-plugin-macros");function a(t,i,n,o){void 0===o&&(o="");var l=i.map(function(i){if(Array.isArray(i))return t.objectProperty(t.stringLiteral(i[0]),a(t,i[1],e.join(n,i[0]),o));try{var l=o.startsWith(".")&&i.endsWith(o)?i:i+o,s=require.resolve("./"+l,{paths:[n]});return t.objectProperty(t.stringLiteral(i.replace(o,"")),t.stringLiteral(r.readFileSync(s,"utf-8")))}catch(e){return null}}).filter(Boolean);if(0===l.length)throw new Error("Cannot resolve file "+o+" in these directories: "+i.join(", "));return t.objectExpression(l)}module.exports=(0,t.createMacro)(function(t){var i=t.state,n=t.babel,o={value:0};t.references.default.forEach(function(t){if("CallExpression"!==t.parentPath.type)throw new Error("This is not supported: `"+t.findParent(n.types.isExpression).getSource()+"`. Please see the raw.macro documentation");!function(t){var i,n=t.referencePath,o=t.usageCounter,l=t.babel.types,s=n.parentPath,u=e.dirname(t.state.file.opts.filename),c=s.get("arguments")[0];switch(c.node.type){case"TemplateLiteral":var f=c.node,v=f.expressions,h=f.quasis;if(0===v.length){i=h[0].value.raw;break}try{if(void 0!==(i=s.get("arguments")[0].evaluate().value))break}catch(e){}if(""===h[0].value.raw)throw new Error("Invalid value, variable interpolation can't be at the start of template literal");if(v.length>2)throw new Error("Invalid value. You can only have 2 dynamic values max. 1 for directory name, 1 for file name.");var d="__raw_dynamic__"+o.value;o.value++;var p=v.map(function(e,r){var t=r!==h.length-1&&c.node.quasis[r+1].value.raw.startsWith("/");return{name:e.name,isDirectory:t}}),m=e.join(u,h[0].value.raw),y=r.readdirSync(m).filter(function(t){try{return r.lstatSync(e.join(m,t)).isDirectory()===p[0].isDirectory}catch(e){return!1}}).flatMap(function(e){return p[0].isDirectory?e:e.endsWith(h[1].value.raw)?e.replace(h[1].value.raw,""):[]});return h.slice(1).forEach(function(t,a){p[a].isDirectory&&y.forEach(function(i,n){if(!t.tail){var o=e.join(m,i),l=r.readdirSync(o).filter(function(e){return e.endsWith(h[a+2].value.raw)});y[n]=[i,l]}})}),function e(r){return r.parentPath?e(r.parentPath):r}(n).unshiftContainer("body",l.variableDeclaration("var",[l.variableDeclarator(l.identifier(d),a(l,y,m,h[h.length-1].value.raw))])),void s.replaceWith(l.expressionStatement(p.reduce(function(e,r){return l.memberExpression(e,l.identifier(r.name),!0)},l.identifier(d))));case"StringLiteral":i=c.node.value}if(void 0===i)throw new Error("There was a problem evaluating the value of the argument for the code: "+s.getSource()+". If the value is dynamic, please make sure that its value is statically deterministic.");var g=require.resolve(i,{paths:[u]}),w=r.readFileSync(g,{encoding:"utf-8"});s.replaceWith(l.expressionStatement(l.stringLiteral(w)))}({referencePath:t,state:i,babel:n,usageCounter:o})})}); | ||
var e=require("path"),r=require("fs"),t=require("babel-plugin-macros");function a(t,n,i,o,l){void 0===o&&(o=""),void 0===l&&(l="utf-8");var s=n.map(function(n){if(Array.isArray(n))return t.objectProperty(t.stringLiteral(n[0]),a(t,n[1],e.join(i,n[0]),o,l));try{var s=o.startsWith(".")&&n.endsWith(o)?n:n+o,u=require.resolve("./"+s,{paths:[i]});return t.objectProperty(t.stringLiteral(n.replace(o,"")),t.stringLiteral(r.readFileSync(u,{encoding:l})))}catch(e){return null}}).filter(Boolean);if(0===s.length)throw new Error("Cannot resolve file "+o+" in these directories: "+n.join(", "));return t.objectExpression(s)}module.exports=(0,t.createMacro)(function(t){var n=t.state,i=t.babel,o={value:0};t.references.default.forEach(function(t){if("CallExpression"!==t.parentPath.type)throw new Error("This is not supported: `"+t.findParent(i.types.isExpression).getSource()+"`. Please see the raw.macro documentation");!function(t){var n,i,o=t.referencePath,l=t.usageCounter,s=t.babel.types,u=o.parentPath,c=e.dirname(t.state.file.opts.filename),f=u.get("arguments"),v=f[0];switch(i=2==f.length&&"StringLiteral"===v.node.type?f[1].node.value:"utf-8",v.node.type){case"TemplateLiteral":var h=v.node,d=h.expressions,p=h.quasis;if(0===d.length){n=p[0].value.raw;break}try{if(void 0!==(n=u.get("arguments")[0].evaluate().value))break}catch(e){}if(""===p[0].value.raw)throw new Error("Invalid value, variable interpolation can't be at the start of template literal");if(d.length>2)throw new Error("Invalid value. You can only have 2 dynamic values max. 1 for directory name, 1 for file name.");var m="__raw_dynamic__"+l.value;l.value++;var y=d.map(function(e,r){var t=r!==p.length-1&&v.node.quasis[r+1].value.raw.startsWith("/");return{name:e.name,isDirectory:t}}),g=e.join(c,p[0].value.raw),w=r.readdirSync(g).filter(function(t){try{return r.lstatSync(e.join(g,t)).isDirectory()===y[0].isDirectory}catch(e){return!1}}).flatMap(function(e){return y[0].isDirectory?e:e.endsWith(p[1].value.raw)?e.replace(p[1].value.raw,""):[]});return p.slice(1).forEach(function(t,a){y[a].isDirectory&&w.forEach(function(n,i){if(!t.tail){var o=e.join(g,n),l=r.readdirSync(o).filter(function(e){return e.endsWith(p[a+2].value.raw)});w[i]=[n,l]}})}),function e(r){return r.parentPath?e(r.parentPath):r}(o).unshiftContainer("body",s.variableDeclaration("var",[s.variableDeclarator(s.identifier(m),a(s,w,g,p[p.length-1].value.raw,i))])),void u.replaceWith(s.expressionStatement(y.reduce(function(e,r){return s.memberExpression(e,s.identifier(r.name),!0)},s.identifier(m))));case"StringLiteral":n=v.node.value}if(void 0===n)throw new Error("There was a problem evaluating the value of the argument for the code: "+u.getSource()+". If the value is dynamic, please make sure that its value is statically deterministic.");var b=require.resolve(n,{paths:[c]}),E=r.readFileSync(b,{encoding:i});u.replaceWith(s.expressionStatement(s.stringLiteral(E)))}({referencePath:t,state:n,babel:i,usageCounter:o})})}); | ||
//# sourceMappingURL=raw.macro.esm.js.map |
@@ -1,2 +0,2 @@ | ||
var e=require("path"),r=require("fs"),t=require("babel-plugin-macros");function a(t,i,n,o){void 0===o&&(o="");var l=i.map(function(i){if(Array.isArray(i))return t.objectProperty(t.stringLiteral(i[0]),a(t,i[1],e.join(n,i[0]),o));try{var l=o.startsWith(".")&&i.endsWith(o)?i:i+o,s=require.resolve("./"+l,{paths:[n]});return t.objectProperty(t.stringLiteral(i.replace(o,"")),t.stringLiteral(r.readFileSync(s,"utf-8")))}catch(e){return null}}).filter(Boolean);if(0===l.length)throw new Error("Cannot resolve file "+o+" in these directories: "+i.join(", "));return t.objectExpression(l)}module.exports=(0,t.createMacro)(function(t){var i=t.state,n=t.babel,o={value:0};t.references.default.forEach(function(t){if("CallExpression"!==t.parentPath.type)throw new Error("This is not supported: `"+t.findParent(n.types.isExpression).getSource()+"`. Please see the raw.macro documentation");!function(t){var i,n=t.referencePath,o=t.usageCounter,l=t.babel.types,s=n.parentPath,u=e.dirname(t.state.file.opts.filename),c=s.get("arguments")[0];switch(c.node.type){case"TemplateLiteral":var f=c.node,v=f.expressions,h=f.quasis;if(0===v.length){i=h[0].value.raw;break}try{if(void 0!==(i=s.get("arguments")[0].evaluate().value))break}catch(e){}if(""===h[0].value.raw)throw new Error("Invalid value, variable interpolation can't be at the start of template literal");if(v.length>2)throw new Error("Invalid value. You can only have 2 dynamic values max. 1 for directory name, 1 for file name.");var d="__raw_dynamic__"+o.value;o.value++;var p=v.map(function(e,r){var t=r!==h.length-1&&c.node.quasis[r+1].value.raw.startsWith("/");return{name:e.name,isDirectory:t}}),m=e.join(u,h[0].value.raw),y=r.readdirSync(m).filter(function(t){try{return r.lstatSync(e.join(m,t)).isDirectory()===p[0].isDirectory}catch(e){return!1}}).flatMap(function(e){return p[0].isDirectory?e:e.endsWith(h[1].value.raw)?e.replace(h[1].value.raw,""):[]});return h.slice(1).forEach(function(t,a){p[a].isDirectory&&y.forEach(function(i,n){if(!t.tail){var o=e.join(m,i),l=r.readdirSync(o).filter(function(e){return e.endsWith(h[a+2].value.raw)});y[n]=[i,l]}})}),function e(r){return r.parentPath?e(r.parentPath):r}(n).unshiftContainer("body",l.variableDeclaration("var",[l.variableDeclarator(l.identifier(d),a(l,y,m,h[h.length-1].value.raw))])),void s.replaceWith(l.expressionStatement(p.reduce(function(e,r){return l.memberExpression(e,l.identifier(r.name),!0)},l.identifier(d))));case"StringLiteral":i=c.node.value}if(void 0===i)throw new Error("There was a problem evaluating the value of the argument for the code: "+s.getSource()+". If the value is dynamic, please make sure that its value is statically deterministic.");var g=require.resolve(i,{paths:[u]}),w=r.readFileSync(g,{encoding:"utf-8"});s.replaceWith(l.expressionStatement(l.stringLiteral(w)))}({referencePath:t,state:i,babel:n,usageCounter:o})})}); | ||
var e=require("path"),r=require("fs"),t=require("babel-plugin-macros");function a(t,n,i,o,l){void 0===o&&(o=""),void 0===l&&(l="utf-8");var s=n.map(function(n){if(Array.isArray(n))return t.objectProperty(t.stringLiteral(n[0]),a(t,n[1],e.join(i,n[0]),o,l));try{var s=o.startsWith(".")&&n.endsWith(o)?n:n+o,u=require.resolve("./"+s,{paths:[i]});return t.objectProperty(t.stringLiteral(n.replace(o,"")),t.stringLiteral(r.readFileSync(u,{encoding:l})))}catch(e){return null}}).filter(Boolean);if(0===s.length)throw new Error("Cannot resolve file "+o+" in these directories: "+n.join(", "));return t.objectExpression(s)}module.exports=(0,t.createMacro)(function(t){var n=t.state,i=t.babel,o={value:0};t.references.default.forEach(function(t){if("CallExpression"!==t.parentPath.type)throw new Error("This is not supported: `"+t.findParent(i.types.isExpression).getSource()+"`. Please see the raw.macro documentation");!function(t){var n,i,o=t.referencePath,l=t.usageCounter,s=t.babel.types,u=o.parentPath,c=e.dirname(t.state.file.opts.filename),f=u.get("arguments"),v=f[0];switch(i=2==f.length&&"StringLiteral"===v.node.type?f[1].node.value:"utf-8",v.node.type){case"TemplateLiteral":var h=v.node,d=h.expressions,p=h.quasis;if(0===d.length){n=p[0].value.raw;break}try{if(void 0!==(n=u.get("arguments")[0].evaluate().value))break}catch(e){}if(""===p[0].value.raw)throw new Error("Invalid value, variable interpolation can't be at the start of template literal");if(d.length>2)throw new Error("Invalid value. You can only have 2 dynamic values max. 1 for directory name, 1 for file name.");var m="__raw_dynamic__"+l.value;l.value++;var y=d.map(function(e,r){var t=r!==p.length-1&&v.node.quasis[r+1].value.raw.startsWith("/");return{name:e.name,isDirectory:t}}),g=e.join(c,p[0].value.raw),w=r.readdirSync(g).filter(function(t){try{return r.lstatSync(e.join(g,t)).isDirectory()===y[0].isDirectory}catch(e){return!1}}).flatMap(function(e){return y[0].isDirectory?e:e.endsWith(p[1].value.raw)?e.replace(p[1].value.raw,""):[]});return p.slice(1).forEach(function(t,a){y[a].isDirectory&&w.forEach(function(n,i){if(!t.tail){var o=e.join(g,n),l=r.readdirSync(o).filter(function(e){return e.endsWith(p[a+2].value.raw)});w[i]=[n,l]}})}),function e(r){return r.parentPath?e(r.parentPath):r}(o).unshiftContainer("body",s.variableDeclaration("var",[s.variableDeclarator(s.identifier(m),a(s,w,g,p[p.length-1].value.raw,i))])),void u.replaceWith(s.expressionStatement(y.reduce(function(e,r){return s.memberExpression(e,s.identifier(r.name),!0)},s.identifier(m))));case"StringLiteral":n=v.node.value}if(void 0===n)throw new Error("There was a problem evaluating the value of the argument for the code: "+u.getSource()+". If the value is dynamic, please make sure that its value is statically deterministic.");var b=require.resolve(n,{paths:[c]}),E=r.readFileSync(b,{encoding:i});u.replaceWith(s.expressionStatement(s.stringLiteral(E)))}({referencePath:t,state:n,babel:i,usageCounter:o})})}); | ||
//# sourceMappingURL=raw.macro.js.map |
@@ -1,2 +0,2 @@ | ||
const e=require("path"),r=require("fs"),{createMacro:t}=require("babel-plugin-macros");function a(t,i,n,o=""){const s=i.map(i=>{if(Array.isArray(i))return t.objectProperty(t.stringLiteral(i[0]),a(t,i[1],e.join(n,i[0]),o));try{const e=o.startsWith(".")&&i.endsWith(o)?i:i+o,a=require.resolve("./"+e,{paths:[n]});return t.objectProperty(t.stringLiteral(i.replace(o,"")),t.stringLiteral(r.readFileSync(a,"utf-8")))}catch(e){return null}}).filter(Boolean);if(0===s.length)throw new Error(`Cannot resolve file ${o} in these directories: ${i.join(", ")}`);return t.objectExpression(s)}module.exports=t(function({references:t,state:i,babel:n}){let o={value:0};t.default.forEach(t=>{if("CallExpression"!==t.parentPath.type)throw new Error(`This is not supported: \`${t.findParent(n.types.isExpression).getSource()}\`. Please see the raw.macro documentation`);!function({referencePath:t,state:i,babel:n,usageCounter:o}){const s=n.types,l=t.parentPath,c=e.dirname(i.file.opts.filename);let u;const h=l.get("arguments")[0];switch(h.node.type){case"TemplateLiteral":{const{expressions:i,quasis:n}=h.node;if(0===i.length){u=n[0].value.raw;break}try{if(u=l.get("arguments")[0].evaluate().value,void 0!==u)break}catch(e){}if(""===n[0].value.raw)throw new Error("Invalid value, variable interpolation can't be at the start of template literal");if(i.length>2)throw new Error("Invalid value. You can only have 2 dynamic values max. 1 for directory name, 1 for file name.");const f="__raw_dynamic__"+o.value;o.value++;const d=i.map((e,r)=>{const t=r!==n.length-1&&h.node.quasis[r+1].value.raw.startsWith("/");return{name:e.name,isDirectory:t}}),p=e.join(c,n[0].value.raw),v=r.readdirSync(p).filter(t=>{try{return r.lstatSync(e.join(p,t)).isDirectory()===d[0].isDirectory}catch(e){return!1}}).flatMap(e=>d[0].isDirectory?e:e.endsWith(n[1].value.raw)?e.replace(n[1].value.raw,""):[]);return n.slice(1).forEach((t,a)=>{d[a].isDirectory&&v.forEach((i,o)=>{if(!t.tail){const t=e.join(p,i),s=r.readdirSync(t).filter(e=>e.endsWith(n[a+2].value.raw));v[o]=[i,s]}})}),function e(r){return r.parentPath?e(r.parentPath):r}(t).unshiftContainer("body",s.variableDeclaration("var",[s.variableDeclarator(s.identifier(f),a(s,v,p,n[n.length-1].value.raw))])),void l.replaceWith(s.expressionStatement(d.reduce((e,r)=>s.memberExpression(e,s.identifier(r.name),!0),s.identifier(f))))}case"StringLiteral":u=h.node.value}if(void 0===u)throw new Error(`There was a problem evaluating the value of the argument for the code: ${l.getSource()}. If the value is dynamic, please make sure that its value is statically deterministic.`);const f=require.resolve(u,{paths:[c]}),d=r.readFileSync(f,{encoding:"utf-8"});l.replaceWith(s.expressionStatement(s.stringLiteral(d)))}({referencePath:t,state:i,babel:n,usageCounter:o})})}); | ||
const e=require("path"),r=require("fs"),{createMacro:t}=require("babel-plugin-macros");function a(t,n,i,o="",s="utf-8"){const l=n.map(n=>{if(Array.isArray(n))return t.objectProperty(t.stringLiteral(n[0]),a(t,n[1],e.join(i,n[0]),o,s));try{const e=o.startsWith(".")&&n.endsWith(o)?n:n+o,a=require.resolve("./"+e,{paths:[i]});return t.objectProperty(t.stringLiteral(n.replace(o,"")),t.stringLiteral(r.readFileSync(a,{encoding:s})))}catch(e){return null}}).filter(Boolean);if(0===l.length)throw new Error(`Cannot resolve file ${o} in these directories: ${n.join(", ")}`);return t.objectExpression(l)}module.exports=t(function({references:t,state:n,babel:i}){let o={value:0};t.default.forEach(t=>{if("CallExpression"!==t.parentPath.type)throw new Error(`This is not supported: \`${t.findParent(i.types.isExpression).getSource()}\`. Please see the raw.macro documentation`);!function({referencePath:t,state:n,babel:i,usageCounter:o}){const s=i.types,l=t.parentPath,c=e.dirname(n.file.opts.filename);let u,h;const f=l.get("arguments"),d=f[0];switch(h=2==f.length&&"StringLiteral"===d.node.type?f[1].node.value:"utf-8",d.node.type){case"TemplateLiteral":{const{expressions:n,quasis:i}=d.node;if(0===n.length){u=i[0].value.raw;break}try{if(u=l.get("arguments")[0].evaluate().value,void 0!==u)break}catch(e){}if(""===i[0].value.raw)throw new Error("Invalid value, variable interpolation can't be at the start of template literal");if(n.length>2)throw new Error("Invalid value. You can only have 2 dynamic values max. 1 for directory name, 1 for file name.");const f="__raw_dynamic__"+o.value;o.value++;const p=n.map((e,r)=>{const t=r!==i.length-1&&d.node.quasis[r+1].value.raw.startsWith("/");return{name:e.name,isDirectory:t}}),v=e.join(c,i[0].value.raw),m=r.readdirSync(v).filter(t=>{try{return r.lstatSync(e.join(v,t)).isDirectory()===p[0].isDirectory}catch(e){return!1}}).flatMap(e=>p[0].isDirectory?e:e.endsWith(i[1].value.raw)?e.replace(i[1].value.raw,""):[]);return i.slice(1).forEach((t,a)=>{p[a].isDirectory&&m.forEach((n,o)=>{if(!t.tail){const t=e.join(v,n),s=r.readdirSync(t).filter(e=>e.endsWith(i[a+2].value.raw));m[o]=[n,s]}})}),function e(r){return r.parentPath?e(r.parentPath):r}(t).unshiftContainer("body",s.variableDeclaration("var",[s.variableDeclarator(s.identifier(f),a(s,m,v,i[i.length-1].value.raw,h))])),void l.replaceWith(s.expressionStatement(p.reduce((e,r)=>s.memberExpression(e,s.identifier(r.name),!0),s.identifier(f))))}case"StringLiteral":u=d.node.value}if(void 0===u)throw new Error(`There was a problem evaluating the value of the argument for the code: ${l.getSource()}. If the value is dynamic, please make sure that its value is statically deterministic.`);const p=require.resolve(u,{paths:[c]}),v=r.readFileSync(p,{encoding:h});l.replaceWith(s.expressionStatement(s.stringLiteral(v)))}({referencePath:t,state:n,babel:i,usageCounter:o})})}); | ||
//# sourceMappingURL=raw.macro.modern.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e){"function"==typeof define&&define.amd?define(e):e()}(function(){var e=require("path"),r=require("fs"),t=require("babel-plugin-macros");function a(t,n,i,o){void 0===o&&(o="");var l=n.map(function(n){if(Array.isArray(n))return t.objectProperty(t.stringLiteral(n[0]),a(t,n[1],e.join(i,n[0]),o));try{var l=o.startsWith(".")&&n.endsWith(o)?n:n+o,s=require.resolve("./"+l,{paths:[i]});return t.objectProperty(t.stringLiteral(n.replace(o,"")),t.stringLiteral(r.readFileSync(s,"utf-8")))}catch(e){return null}}).filter(Boolean);if(0===l.length)throw new Error("Cannot resolve file "+o+" in these directories: "+n.join(", "));return t.objectExpression(l)}module.exports=(0,t.createMacro)(function(t){var n=t.state,i=t.babel,o={value:0};t.references.default.forEach(function(t){if("CallExpression"!==t.parentPath.type)throw new Error("This is not supported: `"+t.findParent(i.types.isExpression).getSource()+"`. Please see the raw.macro documentation");!function(t){var n,i=t.referencePath,o=t.usageCounter,l=t.babel.types,s=i.parentPath,u=e.dirname(t.state.file.opts.filename),c=s.get("arguments")[0];switch(c.node.type){case"TemplateLiteral":var f=c.node,v=f.expressions,h=f.quasis;if(0===v.length){n=h[0].value.raw;break}try{if(void 0!==(n=s.get("arguments")[0].evaluate().value))break}catch(e){}if(""===h[0].value.raw)throw new Error("Invalid value, variable interpolation can't be at the start of template literal");if(v.length>2)throw new Error("Invalid value. You can only have 2 dynamic values max. 1 for directory name, 1 for file name.");var d="__raw_dynamic__"+o.value;o.value++;var p=v.map(function(e,r){var t=r!==h.length-1&&c.node.quasis[r+1].value.raw.startsWith("/");return{name:e.name,isDirectory:t}}),m=e.join(u,h[0].value.raw),y=r.readdirSync(m).filter(function(t){try{return r.lstatSync(e.join(m,t)).isDirectory()===p[0].isDirectory}catch(e){return!1}}).flatMap(function(e){return p[0].isDirectory?e:e.endsWith(h[1].value.raw)?e.replace(h[1].value.raw,""):[]});return h.slice(1).forEach(function(t,a){p[a].isDirectory&&y.forEach(function(n,i){if(!t.tail){var o=e.join(m,n),l=r.readdirSync(o).filter(function(e){return e.endsWith(h[a+2].value.raw)});y[i]=[n,l]}})}),function e(r){return r.parentPath?e(r.parentPath):r}(i).unshiftContainer("body",l.variableDeclaration("var",[l.variableDeclarator(l.identifier(d),a(l,y,m,h[h.length-1].value.raw))])),void s.replaceWith(l.expressionStatement(p.reduce(function(e,r){return l.memberExpression(e,l.identifier(r.name),!0)},l.identifier(d))));case"StringLiteral":n=c.node.value}if(void 0===n)throw new Error("There was a problem evaluating the value of the argument for the code: "+s.getSource()+". If the value is dynamic, please make sure that its value is statically deterministic.");var g=require.resolve(n,{paths:[u]}),w=r.readFileSync(g,{encoding:"utf-8"});s.replaceWith(l.expressionStatement(l.stringLiteral(w)))}({referencePath:t,state:n,babel:i,usageCounter:o})})})}); | ||
!function(e){"function"==typeof define&&define.amd?define(e):e()}(function(){var e=require("path"),r=require("fs"),t=require("babel-plugin-macros");function a(t,n,i,o,l){void 0===o&&(o=""),void 0===l&&(l="utf-8");var s=n.map(function(n){if(Array.isArray(n))return t.objectProperty(t.stringLiteral(n[0]),a(t,n[1],e.join(i,n[0]),o,l));try{var s=o.startsWith(".")&&n.endsWith(o)?n:n+o,u=require.resolve("./"+s,{paths:[i]});return t.objectProperty(t.stringLiteral(n.replace(o,"")),t.stringLiteral(r.readFileSync(u,{encoding:l})))}catch(e){return null}}).filter(Boolean);if(0===s.length)throw new Error("Cannot resolve file "+o+" in these directories: "+n.join(", "));return t.objectExpression(s)}module.exports=(0,t.createMacro)(function(t){var n=t.state,i=t.babel,o={value:0};t.references.default.forEach(function(t){if("CallExpression"!==t.parentPath.type)throw new Error("This is not supported: `"+t.findParent(i.types.isExpression).getSource()+"`. Please see the raw.macro documentation");!function(t){var n,i,o=t.referencePath,l=t.usageCounter,s=t.babel.types,u=o.parentPath,c=e.dirname(t.state.file.opts.filename),f=u.get("arguments"),v=f[0];switch(i=2==f.length&&"StringLiteral"===v.node.type?f[1].node.value:"utf-8",v.node.type){case"TemplateLiteral":var d=v.node,h=d.expressions,p=d.quasis;if(0===h.length){n=p[0].value.raw;break}try{if(void 0!==(n=u.get("arguments")[0].evaluate().value))break}catch(e){}if(""===p[0].value.raw)throw new Error("Invalid value, variable interpolation can't be at the start of template literal");if(h.length>2)throw new Error("Invalid value. You can only have 2 dynamic values max. 1 for directory name, 1 for file name.");var m="__raw_dynamic__"+l.value;l.value++;var y=h.map(function(e,r){var t=r!==p.length-1&&v.node.quasis[r+1].value.raw.startsWith("/");return{name:e.name,isDirectory:t}}),g=e.join(c,p[0].value.raw),w=r.readdirSync(g).filter(function(t){try{return r.lstatSync(e.join(g,t)).isDirectory()===y[0].isDirectory}catch(e){return!1}}).flatMap(function(e){return y[0].isDirectory?e:e.endsWith(p[1].value.raw)?e.replace(p[1].value.raw,""):[]});return p.slice(1).forEach(function(t,a){y[a].isDirectory&&w.forEach(function(n,i){if(!t.tail){var o=e.join(g,n),l=r.readdirSync(o).filter(function(e){return e.endsWith(p[a+2].value.raw)});w[i]=[n,l]}})}),function e(r){return r.parentPath?e(r.parentPath):r}(o).unshiftContainer("body",s.variableDeclaration("var",[s.variableDeclarator(s.identifier(m),a(s,w,g,p[p.length-1].value.raw,i))])),void u.replaceWith(s.expressionStatement(y.reduce(function(e,r){return s.memberExpression(e,s.identifier(r.name),!0)},s.identifier(m))));case"StringLiteral":n=v.node.value}if(void 0===n)throw new Error("There was a problem evaluating the value of the argument for the code: "+u.getSource()+". If the value is dynamic, please make sure that its value is statically deterministic.");var b=require.resolve(n,{paths:[c]}),E=r.readFileSync(b,{encoding:i});u.replaceWith(s.expressionStatement(s.stringLiteral(E)))}({referencePath:t,state:n,babel:i,usageCounter:o})})})}); | ||
//# sourceMappingURL=raw.macro.umd.js.map |
{ | ||
"name": "raw.macro", | ||
"description": "Read file contents at build time, similar to webpack raw-loader", | ||
"version": "0.4.2", | ||
"version": "0.5.0", | ||
"engines": { | ||
"node": ">=8.9.0" | ||
"node": ">=12.0.0" | ||
}, | ||
@@ -8,0 +8,0 @@ "source": "src/macro.js", |
declare module "raw.macro" { | ||
export default function raw(rawPath: string): string; | ||
export default function raw(rawPath: string, encoding?: string): string; | ||
} |
# raw.macro | ||
[![Build Status](https://travis-ci.org/pveyes/raw.macro.svg?branch=master)](https://travis-ci.org/pveyes/raw.macro) [![Babel Macro](https://img.shields.io/badge/babel--macro-%F0%9F%8E%A3-f5da55.svg?style=flat-square)](https://github.com/kentcdodds/babel-plugin-macros) [![Greenkeeper badge](https://badges.greenkeeper.io/pveyes/raw.macro.svg)](https://greenkeeper.io/) | ||
[![Actions Status](https://github.com/pveyes/raw.macro/workflows/build/badge.svg)](https://github.com/pveyes/raw.macro/actions) [![Babel Macro](https://img.shields.io/badge/babel--macro-%F0%9F%8E%A3-f5da55.svg?style=flat-square)](https://github.com/kentcdodds/babel-plugin-macros) | ||
@@ -13,5 +13,8 @@ > Webpack [`raw-loader`](https://github.com/webpack-contrib/raw-loader) implemented as [`babel-plugin-macros`](https://github.com/kentcdodds/babel-plugin-macros) | ||
$ yarn add --dev raw.macro | ||
# or | ||
$ npm install --save-dev raw.macro | ||
``` | ||
Make sure `babel-plugin-macros` already installed. If you're using [Create React App](https://github.com/facebook/create-react-app), it's installed by default. | ||
## Usage | ||
@@ -18,0 +21,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
62602
54
54