Skip to content

Instantly share code, notes, and snippets.

@kumavis
Created August 19, 2020 02:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kumavis/b58078cbe935a2bd3e9313d133c7d49a to your computer and use it in GitHub Desktop.
Save kumavis/b58078cbe935a2bd3e9313d133c7d49a to your computer and use it in GitHub Desktop.
const { builtinModules: builtinPackages } = require('module')
// lavamoat-core@5.0.0
const { createModuleInspector } = require('lavamoat-core')
const inspector = createModuleInspector({
// used to see if this imports builtins
isBuiltin: (name) => builtinPackages.includes(name),
// adds some notes on ses compat, etc
includeDebugInfo: true,
})
inspector.inspectModule({
// unique name, may be same as filename
specifier: 'string',
// filename
file: 'node_modules/xyz/index.js'
// does not include version
packageName: '',
// { js, builtin, native }
type: 'js',
// the code, no module initializer wrapper
content: 'module.exports = 42',
// key is requestedName, value is specifier
importMap: {
'./util': 'node_modules/xyz/util.js'
},
// (optional) pregenerated babel ast
ast: undefined,
})
const config = inspector.generateConfig()
// package policy is here
// config.resouces[packageName]
// debug info is here
// config.debugInfo[moduleSpecifier]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment