babel-transform-roll20
Advanced tools
Comparing version 0.1.0 to 0.2.0
{ | ||
"name": "babel-transform-roll20", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "A babel transform tool for transpiling scripts for the Roll20 sandbox.", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -8,8 +8,22 @@ const babelParser = require('@babel/parser') | ||
module.exports = function roll20Transform ({ types: t }) { | ||
function guaranteeModulePath (programPath, modulePath, moduleName) { | ||
if (!programPath.__visited_files[modulePath]) { | ||
const moduleContents = fs.readFileSync(modulePath, { | ||
function getFileContents (filePath) { | ||
try { | ||
return fs.readFileSync(filePath, { | ||
encoding: 'UTF-8' | ||
}) | ||
} catch (exception) { | ||
if (exception.code !== 'ENOENT') { | ||
throw exception | ||
} | ||
return fs.readFileSync(filePath.slice(0, -3) + '/index.js', { | ||
encoding: 'UTF-8' | ||
}) | ||
} | ||
} | ||
function guaranteeModulePath (programPath, modulePath, moduleName) { | ||
if (!programPath.__visited_files[modulePath]) { | ||
const moduleContents = getFileContents(modulePath) | ||
const parsedModule = babelParser.parse(moduleContents, { | ||
@@ -38,2 +52,4 @@ sourceType: 'module' | ||
)) | ||
programPath.__visited_files[modulePath] = true | ||
} | ||
@@ -118,3 +134,8 @@ } | ||
const modulePath = `/${roots.join('/')}${fileName}.js` | ||
let rootsPath = roots.join('/') | ||
if (!rootsPath.endsWith('/')) { | ||
rootsPath += '/' | ||
} | ||
const modulePath = `/${rootsPath}${fileName}.js` | ||
const moduleName = `'${modulePath.slice(process.cwd().length + 1, -3)}'` | ||
@@ -238,3 +259,8 @@ const exportName = `__export__${modulePath.slice(process.cwd().length + 1, -3).replace(/[\/-]/g, '_')}` | ||
const modulePath = `/${programPath.__roots.join('/')}${fileName}.js` | ||
let rootsPath = programPath.__roots.join('/') | ||
if (!rootsPath.endsWith('/')) { | ||
rootsPath += '/' | ||
} | ||
const modulePath = `/${rootsPath}${fileName}.js` | ||
const moduleName = `'${modulePath.slice(process.cwd().length + 1, -3)}'` | ||
@@ -294,4 +320,2 @@ | ||
) | ||
programPath.__visited_files[fileName] = true | ||
}, | ||
@@ -298,0 +322,0 @@ exit (path) { |
@@ -1,3 +0,3 @@ | ||
import * as objects from './export-all/objects' | ||
import * as objects from './import-all/objects' | ||
console.log(objects.objectA, objects.objectB) |
@@ -74,1 +74,8 @@ import * as babel from '@babel/core' | ||
}) | ||
test('transforms index imports', async (t) => { | ||
const result = await loadFile('./test/transforms/index-import.js') | ||
const { code } = await transform('./test/fixtures/index-import.js') | ||
t.is(code, result) | ||
}) |
const modules = {}; | ||
modules['test/fixtures/export-all/object-b'] = (function () { | ||
modules['test/fixtures/import-all/object-b'] = (function () { | ||
const objectB = { | ||
@@ -10,3 +10,3 @@ key: 'value' | ||
})() | ||
modules['test/fixtures/export-all/object-a'] = (function () { | ||
modules['test/fixtures/import-all/object-a'] = (function () { | ||
const objectA = { | ||
@@ -19,8 +19,8 @@ key: 'value' | ||
})() | ||
modules['test/fixtures/export-all/objects'] = (function () { | ||
const __export__test_fixtures_export_all_object_a = modules['test/fixtures/export-all/object-a']; | ||
const __export__test_fixtures_export_all_object_b = modules['test/fixtures/export-all/object-b']; | ||
return Object.assign({}, __export__test_fixtures_export_all_object_a, __export__test_fixtures_export_all_object_b, {}); | ||
modules['test/fixtures/import-all/objects'] = (function () { | ||
const __export__test_fixtures_import_all_object_a = modules['test/fixtures/import-all/object-a']; | ||
const __export__test_fixtures_import_all_object_b = modules['test/fixtures/import-all/object-b']; | ||
return Object.assign({}, __export__test_fixtures_import_all_object_a, __export__test_fixtures_import_all_object_b, {}); | ||
})() | ||
const objects = modules['test/fixtures/export-all/objects']; | ||
const objects = modules['test/fixtures/import-all/objects']; | ||
console.log(objects.objectA, objects.objectB); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21094
32
627