diff --git a/README.md b/README.md index bc0d2fa3c..f8fd59186 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,13 @@ JavaScript client agent for the AppMap framework To install: ```sh -npm install @appland/appmap-agent-js +npm install @appland/appmap-agent-js ``` To run: ```sh +npx appmap + APPMAP_OUTPUT_DIR=. npx appmap -- standalone-file.js argv0 argv1 ``` diff --git a/bin/inline.mjs b/bin/inline.mjs index e69de29bb..e6f64e992 100644 --- a/bin/inline.mjs +++ b/bin/inline.mjs @@ -0,0 +1,4 @@ +import minimist from 'minimist'; +import main from '../lib/server/inline-main.mjs'; + +main(minimist(process.argv.slice(2))); diff --git a/dist/inline.js b/dist/inline-channel.js similarity index 94% rename from dist/inline.js rename to dist/inline-channel.js index 0cfed6c08..d2cf50922 100644 --- a/dist/inline.js +++ b/dist/inline-channel.js @@ -10,46 +10,22 @@ var escodegen = require('escodegen'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } -function _interopNamespace(e) { - if (e && e.__esModule) return e; - var n = Object.create(null); - if (e) { - Object.keys(e).forEach(function (k) { - if (k !== 'default') { - var d = Object.getOwnPropertyDescriptor(e, k); - Object.defineProperty(n, k, d.get ? d : { - enumerable: true, - get: function () { - return e[k]; - } - }); - } - }); - } - n['default'] = e; - return Object.freeze(n); -} - -var FileSystem__namespace = /*#__PURE__*/_interopNamespace(FileSystem); var Yaml__default = /*#__PURE__*/_interopDefaultLegacy(Yaml); -var Util__namespace = /*#__PURE__*/_interopNamespace(Util); -var Path__namespace = /*#__PURE__*/_interopNamespace(Path); -var ChildProcess__namespace = /*#__PURE__*/_interopNamespace(ChildProcess); // I'm not about the debuglog api because modifying process.env.NODE_DEBUG has no effect. // Why not directly provide the optimize logging function then? // https://github.com/nodejs/node/blob/master/lib/internal/util/debuglog.js const logger = { - error: Util__namespace.debuglog('appmap-error', (log) => { + error: Util.debuglog('appmap-error', (log) => { logger.error = log; }), - warning: Util__namespace.debuglog('appmap-warning', (log) => { + warning: Util.debuglog('appmap-warning', (log) => { logger.warning = log; }), - info: Util__namespace.debuglog('appmap-info', (log) => { + info: Util.debuglog('appmap-info', (log) => { logger.info = log; - }) + }), }; const DEFAULT_ENABLED = false; @@ -66,13 +42,13 @@ const combine = (closure1, closure2) => (any) => closure2(closure1(any)); const isNotNull = (any) => any !== null; -const trim$1 = (string) => string.trim(); +const trim = (string) => string.trim(); const toLowerCase = (string) => string.toLowerCase(); const identity = (any) => any; -const isAppmapEnvKey = (key) => key === "APPMAP" || key.startsWith("APPMAP_"); +const isAppmapEnvKey = (key) => key === 'APPMAP' || key.startsWith('APPMAP_'); ////////////// // Sanitize // @@ -194,11 +170,11 @@ const mappings = { }, APPMAP_EXCLUDE: { name: 'exclusions', - sanitize: (string) => string.split(',').map(trim$1), + sanitize: (string) => string.split(',').map(trim), }, APPMAP_PACKAGES: { name: 'packages', - sanitize: (string) => string.split(',').map(trim$1).map(wrapName), + sanitize: (string) => string.split(',').map(trim).map(wrapName), }, }, json: { @@ -223,8 +199,8 @@ const mappings = { 'language-version value', DEFAULT_LANGUAGE_VERSION, ), - makeLanguageVersionSanitizer() - ) + makeLanguageVersionSanitizer(), + ), }, 'escape-prefix': { name: 'escape_prefix', @@ -247,46 +223,42 @@ const mappings = { }, 'git-dir': { name: 'git_dir', - sanitize: makeTypeSanitizer( - 'string', - 'git-dir value', - DEFAULT_GIT_DIR, - ), + sanitize: makeTypeSanitizer('string', 'git-dir value', DEFAULT_GIT_DIR), }, packages: { name: 'packages', sanitize: makeArraySanitizer('output_dir conf value', (json, index) => { - if (typeof json === 'string') { - return { name: json }; + if (typeof json === 'string') { + return { name: json }; + } + if (typeof json === 'object' && json !== null) { + if (Reflect.getOwnPropertyDescriptor(json, 'name') === undefined) { + logger.warning( + 'Invalid packages[%i] value >> missing name field and got %s', + index, + json, + ); + return null; } - if (typeof json === 'object' && json !== null) { - if (Reflect.getOwnPropertyDescriptor(json, 'name') === undefined) { - logger.warning( - 'Invalid packages[%i] value >> missing name field and got %s', - index, - json, - ); - return null; - } - if (typeof json.name !== 'string') { - logger.warning( - 'Invalid packages[%i].name value >> expected a string and got %s', - index, - json.name, - ); - return null; - } - return { - name: json.name, - }; + if (typeof json.name !== 'string') { + logger.warning( + 'Invalid packages[%i].name value >> expected a string and got %s', + index, + json.name, + ); + return null; } - logger.warning( - 'Invalid packages[%i] value >> expected either a string or an object and got %s', - index, - json, - ); - return null; - }), + return { + name: json.name, + }; + } + logger.warning( + 'Invalid packages[%i] value >> expected either a string or an object and got %s', + index, + json, + ); + return null; + }), }, exclude: { name: 'exclusions', @@ -336,7 +308,7 @@ const extend = (mapping, conf, object) => { const { name, sanitize } = mapping[key]; conf[name] = mergers[name](conf[name], sanitize(object[key])); } else { - logger.warning("Unrecognized conf key %s", key); + logger.warning('Unrecognized conf key %s', key); } }); return conf; @@ -357,7 +329,7 @@ const extendWithPath = (conf, path) => { } let content; try { - content = FileSystem__namespace.readFileSync(path, 'utf8'); + content = FileSystem.readFileSync(path, 'utf8'); } catch (error) { logger.warning('Failed to read conf file at %s >> %s', path, error.message); return undefined; @@ -398,10 +370,19 @@ const extendWithEnv = (conf, env) => { if (Reflect.getOwnPropertyDescriptor(env, 'APPMAP_CONFIG') !== undefined) { conf = extendWithPath(conf, env.APPMAP_CONFIG); } - return extend(mappings.env, conf, Reflect.ownKeys(env).filter(isAppmapEnvKey).reduce((acc, key) => { - acc[key] = env[key]; - return acc; - }, {__proto__:null})); + return extend( + mappings.env, + conf, + Reflect.ownKeys(env) + .filter(isAppmapEnvKey) + .reduce( + (acc, key) => { + acc[key] = env[key]; + return acc; + }, + { __proto__: null }, + ), + ); }; //////////// @@ -412,10 +393,10 @@ class Config { constructor(conf) { this.conf = conf; } - extendWithJson (json) { + extendWithJson(json) { return new Config(extendWithJson(this.conf, json)); } - extendWithPath (path) { + extendWithPath(path) { return new Config(extendWithPath(this.conf, path)); } extendWithEnv(env) { @@ -531,13 +512,13 @@ var Namespace = (class Namespace { } }); -const trim = (string) => string.trim(); +const trim$1 = (string) => string.trim(); const format = (command, path, reason, detail, stderr) => `Command failure cwd=${path}: ${command} >> ${reason} ${detail} ${stderr}`; const spawnSync = (command, path) => { - const result = ChildProcess__namespace.spawnSync( + const result = ChildProcess.spawnSync( command.split(' ')[0], command.split(' ').slice(1), { @@ -576,7 +557,7 @@ const parseStatus = (status) => { return null; } /* c8 ignore stop */ - return status.split('\n').map(trim); + return status.split('\n').map(trim$1); }; const parseDescription = (description) => { @@ -641,7 +622,7 @@ class File { version, source, path, - content = FileSystem__namespace.readFileSync(path, 'utf8'), + content = FileSystem.readFileSync(path, 'utf8'), ) { this.path = path; this.version = version; @@ -2101,18 +2082,22 @@ var instrument = (file, namespace, callback) => { return escodegen.generate(getResultNode(result)); }; -var dirname_1 = __dirname; +// import { home } from '../../home.js'; const APPMAP_VERSION = '1.4'; -const client = JSON.parse(FileSystem__namespace.readFileSync( - Path__namespace.join( - dirname_1, - '..', - 'package.json', - ), - 'utf8', -)); +const client = { + name: "@appland/appmap-agent-js", + repository: { + type: "git", + url: "https://github.com/applandinc/appmap-agent-js.git" + }, + version: "???", +}; + +// const client = JSON.parse( +// FileSystem.readFileSync(Path.join(home, 'package.json'), 'utf8'), +// ); var Appmap = (class Appmap { constructor() { @@ -2186,13 +2171,13 @@ var Appmap = (class Appmap { logger.error('Appmap cannot be terminated because it is idle'); } else { logger.info('Appmap terminate with: %j', reason); - const path = Path__namespace.join( + const path = Path.join( this.state.config.getOutputDir(), `${this.state.config.getMapName()}.appmap.json`, ); const content = JSON.stringify(this.state.appmap); try { - FileSystem__namespace.writeFileSync(path, content, 'utf8'); + FileSystem.writeFileSync(path, content, 'utf8'); } catch (error) { logger.error( 'Appmap cannot be saved at %s because %s; outputing to stdout instead', @@ -2210,7 +2195,7 @@ var Appmap = (class Appmap { const RECORDER_NAME = 'node-inline'; -var inline = (env) => { +var inlineChannel = (env) => { const appmap = new Appmap(); return { initialize: (init) => { @@ -2234,4 +2219,4 @@ var inline = (env) => { }; }; -module.exports = inline; +module.exports = inlineChannel; diff --git a/home.js b/home.js new file mode 100644 index 000000000..efed990db --- /dev/null +++ b/home.js @@ -0,0 +1,2 @@ + +exports.home = __dirname; diff --git a/lib/client/es2015/node/channel/inline.js b/lib/client/es2015/node/channel/inline.js index 44bf5c895..25d2e3b09 100644 --- a/lib/client/es2015/node/channel/inline.js +++ b/lib/client/es2015/node/channel/inline.js @@ -1 +1 @@ -module.exports = require("../../../../../dist/inline.js"); +module.exports = require("../../../../../dist/inline-channel.js"); diff --git a/lib/dirname.js b/lib/dirname.js deleted file mode 100644 index 738a08c40..000000000 --- a/lib/dirname.js +++ /dev/null @@ -1,2 +0,0 @@ - -exports.dirname = __dirname; diff --git a/lib/server/appmap.mjs b/lib/server/appmap.mjs index 01753264c..c6c9f5106 100644 --- a/lib/server/appmap.mjs +++ b/lib/server/appmap.mjs @@ -5,18 +5,25 @@ import Namespace from './namespace.mjs'; import git from './git.mjs'; import File from './file.mjs'; import instrument from './instrument/index.mjs'; -import {dirname} from "../dirname.js"; const APPMAP_VERSION = '1.4'; -const client = JSON.parse(FileSystem.readFileSync( - Path.join( - dirname, - '..', - 'package.json', - ), - 'utf8', -)); +// Getting the right version: +// +// import { home } from '../../home.js'; +// npx rollup --plugin commonjs +// const client = JSON.parse( +// FileSystem.readFileSync(Path.join(home, 'package.json'), 'utf8'), +// ); + +const client = { + name: "@appland/appmap-agent-js", + repository: { + type: "git", + url: "https://github.com/applandinc/appmap-agent-js.git" + }, + version: "???", +}; export default (class Appmap { constructor() { diff --git a/lib/server/config.mjs b/lib/server/config.mjs index a2a0230b5..4853d14ab 100644 --- a/lib/server/config.mjs +++ b/lib/server/config.mjs @@ -22,7 +22,7 @@ const toLowerCase = (string) => string.toLowerCase(); const identity = (any) => any; -const isAppmapEnvKey = (key) => key === "APPMAP" || key.startsWith("APPMAP_"); +const isAppmapEnvKey = (key) => key === 'APPMAP' || key.startsWith('APPMAP_'); ////////////// // Sanitize // @@ -175,8 +175,8 @@ const mappings = { 'language-version value', DEFAULT_LANGUAGE_VERSION, ), - makeLanguageVersionSanitizer('language-version value') - ) + makeLanguageVersionSanitizer('language-version value'), + ), }, 'escape-prefix': { name: 'escape_prefix', @@ -199,46 +199,42 @@ const mappings = { }, 'git-dir': { name: 'git_dir', - sanitize: makeTypeSanitizer( - 'string', - 'git-dir value', - DEFAULT_GIT_DIR, - ), + sanitize: makeTypeSanitizer('string', 'git-dir value', DEFAULT_GIT_DIR), }, packages: { name: 'packages', sanitize: makeArraySanitizer('output_dir conf value', (json, index) => { - if (typeof json === 'string') { - return { name: json }; + if (typeof json === 'string') { + return { name: json }; + } + if (typeof json === 'object' && json !== null) { + if (Reflect.getOwnPropertyDescriptor(json, 'name') === undefined) { + logger.warning( + 'Invalid packages[%i] value >> missing name field and got %s', + index, + json, + ); + return null; } - if (typeof json === 'object' && json !== null) { - if (Reflect.getOwnPropertyDescriptor(json, 'name') === undefined) { - logger.warning( - 'Invalid packages[%i] value >> missing name field and got %s', - index, - json, - ); - return null; - } - if (typeof json.name !== 'string') { - logger.warning( - 'Invalid packages[%i].name value >> expected a string and got %s', - index, - json.name, - ); - return null; - } - return { - name: json.name, - }; + if (typeof json.name !== 'string') { + logger.warning( + 'Invalid packages[%i].name value >> expected a string and got %s', + index, + json.name, + ); + return null; } - logger.warning( - 'Invalid packages[%i] value >> expected either a string or an object and got %s', - index, - json, - ); - return null; - }), + return { + name: json.name, + }; + } + logger.warning( + 'Invalid packages[%i] value >> expected either a string or an object and got %s', + index, + json, + ); + return null; + }), }, exclude: { name: 'exclusions', @@ -288,7 +284,7 @@ const extend = (mapping, conf, object) => { const { name, sanitize } = mapping[key]; conf[name] = mergers[name](conf[name], sanitize(object[key])); } else { - logger.warning("Unrecognized conf key %s", key); + logger.warning('Unrecognized conf key %s', key); } }); return conf; @@ -350,10 +346,19 @@ const extendWithEnv = (conf, env) => { if (Reflect.getOwnPropertyDescriptor(env, 'APPMAP_CONFIG') !== undefined) { conf = extendWithPath(conf, env.APPMAP_CONFIG); } - return extend(mappings.env, conf, Reflect.ownKeys(env).filter(isAppmapEnvKey).reduce((acc, key) => { - acc[key] = env[key]; - return acc; - }, {__proto__:null})); + return extend( + mappings.env, + conf, + Reflect.ownKeys(env) + .filter(isAppmapEnvKey) + .reduce( + (acc, key) => { + acc[key] = env[key]; + return acc; + }, + { __proto__: null }, + ), + ); }; //////////// @@ -364,10 +369,10 @@ class Config { constructor(conf) { this.conf = conf; } - extendWithJson (json) { + extendWithJson(json) { return new Config(extendWithJson(this.conf, json)); } - extendWithPath (path) { + extendWithPath(path) { return new Config(extendWithPath(this.conf, path)); } extendWithEnv(env) { diff --git a/lib/server/inline.mjs b/lib/server/inline-channel.mjs similarity index 100% rename from lib/server/inline.mjs rename to lib/server/inline-channel.mjs diff --git a/lib/server/inline-main.mjs b/lib/server/inline-main.mjs new file mode 100644 index 000000000..325797684 --- /dev/null +++ b/lib/server/inline-main.mjs @@ -0,0 +1,54 @@ +import * as ChildProcess from 'child_process'; +import logger from './logger.mjs'; +import { home } from '../../home.js'; + +const mapping = { + __proto__: null, + cjs: null, + mjs: null, + 'output-dir': 'APPMAP_OUTPUT_DIR', + 'app-name': 'APPMAP_APP_NAME', + 'map-name': 'APPMAP_MAP_NAME', +}; + +export default ((argv) => { + console.log(argv); + const env = Reflect.ownKeys(argv).reduce( + (acc, key) => { + if (key in mapping) { + if (mapping[key] !== null) { + acc[mapping[key]] = argv[key]; + } + } else { + logger.warning('Unknown cli argument: %s', key); + } + return acc; + }, + { __proto__: null }, + ); + if (Reflect.getOwnPropertyDescriptor(argv, 'mjs') && argv.mjs) { + let name; + if (Reflect.getOwnPropertyDescriptor(argv, 'cjs') && argv.cjs) { + logger.info('Hooking both mjs and cjs module'); + name = 'main-both.js'; + } else { + logger.info('Hooking only mjs module'); + name = 'main-mjs.js'; + } + return ChildProcess.spawn( + 'node', + ['--experimental-loader', `${home}/lib/client/es2015/node/${name}`, ...argv._], + { env }, + ); + } + if (Reflect.getOwnPropertyDescriptor(argv, 'cjs') && argv.cjs) { + logger.info('Hooking only cjs module'); + return ChildProcess.spawn( + 'node', + ['--require', `${home}/lib/client/es2015/node/main-cjs.js`, ...argv._], + { env }, + ); + } + logger.warning('Not hooking anything (expected either --cjs or --mjs)'); + return ChildProcess.spawn('node', argv._); +}); diff --git a/lib/server/logger.mjs b/lib/server/logger.mjs index 3f1e25759..44763aff6 100644 --- a/lib/server/logger.mjs +++ b/lib/server/logger.mjs @@ -13,7 +13,7 @@ const logger = { }), info: Util.debuglog('appmap-info', (log) => { logger.info = log; - }) + }), }; export default logger; diff --git a/package-lock.json b/package-lock.json index e595437ae..9042227fc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,6 @@ "appmap": "bin/agent.mjs" }, "devDependencies": { - "@rollup/plugin-commonjs": "^18.0.0", "@semantic-release/changelog": "^5.0.1", "@semantic-release/git": "^9.0.0", "c8": "^7.6.0", @@ -565,50 +564,6 @@ "node": ">=8" } }, - "node_modules/@rollup/plugin-commonjs": { - "version": "18.0.0", - "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-18.0.0.tgz", - "integrity": "sha512-fj92shhg8luw7XbA0HowAqz90oo7qtLGwqTKbyZ8pmOyH8ui5e+u0wPEgeHLH3djcVma6gUCUrjY6w5R2o1u6g==", - "dev": true, - "dependencies": { - "@rollup/pluginutils": "^3.1.0", - "commondir": "^1.0.1", - "estree-walker": "^2.0.1", - "glob": "^7.1.6", - "is-reference": "^1.2.1", - "magic-string": "^0.25.7", - "resolve": "^1.17.0" - }, - "engines": { - "node": ">= 8.0.0" - }, - "peerDependencies": { - "rollup": "^2.30.0" - } - }, - "node_modules/@rollup/pluginutils": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-3.1.0.tgz", - "integrity": "sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==", - "dev": true, - "dependencies": { - "@types/estree": "0.0.39", - "estree-walker": "^1.0.1", - "picomatch": "^2.2.2" - }, - "engines": { - "node": ">= 8.0.0" - }, - "peerDependencies": { - "rollup": "^1.20.0||^2.0.0" - } - }, - "node_modules/@rollup/pluginutils/node_modules/estree-walker": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-1.0.1.tgz", - "integrity": "sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==", - "dev": true - }, "node_modules/@semantic-release/changelog": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/@semantic-release/changelog/-/changelog-5.0.1.tgz", @@ -690,12 +645,6 @@ "node": ">=8.12.0" } }, - "node_modules/@types/estree": { - "version": "0.0.39", - "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz", - "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==", - "dev": true - }, "node_modules/@types/is-windows": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@types/is-windows/-/is-windows-1.0.0.tgz", @@ -2413,12 +2362,6 @@ "node": ">=4.0" } }, - "node_modules/estree-walker": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz", - "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", - "dev": true - }, "node_modules/esutils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", @@ -3042,21 +2985,6 @@ "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "dev": true }, - "node_modules/fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "dev": true, - "hasInstallScript": true, - "optional": true, - "os": [ - "darwin" - ], - "peer": true, - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } - }, "node_modules/function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", @@ -3737,15 +3665,6 @@ "node": ">= 0.4" } }, - "node_modules/is-reference": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.2.1.tgz", - "integrity": "sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==", - "dev": true, - "dependencies": { - "@types/estree": "*" - } - }, "node_modules/is-regex": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.2.tgz", @@ -4133,15 +4052,6 @@ "node": ">=10" } }, - "node_modules/magic-string": { - "version": "0.25.7", - "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.7.tgz", - "integrity": "sha512-4CrMT5DOHTDk4HYDlzmwu4FVCcIYI8gauveasrdCu2IKIFOJ3f0v/8MDGJCDL9oD2ppz/Av1b0Nj345H9M+XIA==", - "dev": true, - "dependencies": { - "sourcemap-codec": "^1.4.4" - } - }, "node_modules/make-dir": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", @@ -9551,22 +9461,6 @@ "rimraf": "bin.js" } }, - "node_modules/rollup": { - "version": "2.44.0", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.44.0.tgz", - "integrity": "sha512-rGSF4pLwvuaH/x4nAS+zP6UNn5YUDWf/TeEU5IoXSZKBbKRNTCI3qMnYXKZgrC0D2KzS2baiOZt1OlqhMu5rnQ==", - "dev": true, - "peer": true, - "bin": { - "rollup": "dist/bin/rollup" - }, - "engines": { - "node": ">=10.0.0" - }, - "optionalDependencies": { - "fsevents": "~2.3.1" - } - }, "node_modules/run-async": { "version": "2.4.1", "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.4.1.tgz", @@ -9965,12 +9859,6 @@ "integrity": "sha512-cPiFOTLUKvJFIg4SKVScy4ilPPW6rFgMgfuZJPNoDuMs3nC1HbMUycBoJw77xFIp6z1UJQJOfx6C9GMH80DiTw==", "dev": true }, - "node_modules/sourcemap-codec": { - "version": "1.4.8", - "resolved": "https://registry.npmjs.org/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz", - "integrity": "sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==", - "dev": true - }, "node_modules/spawn-wrap": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/spawn-wrap/-/spawn-wrap-2.0.0.tgz", @@ -11273,40 +11161,6 @@ "integrity": "sha512-ZXRY4jNvVgSVQ8DL3LTcakaAtXwTVUxE81hslsyD2AtoXW/wVob10HkOJ1X/pAlcI7D+2YoZKg5do8G/w6RYgA==", "dev": true }, - "@rollup/plugin-commonjs": { - "version": "18.0.0", - "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-18.0.0.tgz", - "integrity": "sha512-fj92shhg8luw7XbA0HowAqz90oo7qtLGwqTKbyZ8pmOyH8ui5e+u0wPEgeHLH3djcVma6gUCUrjY6w5R2o1u6g==", - "dev": true, - "requires": { - "@rollup/pluginutils": "^3.1.0", - "commondir": "^1.0.1", - "estree-walker": "^2.0.1", - "glob": "^7.1.6", - "is-reference": "^1.2.1", - "magic-string": "^0.25.7", - "resolve": "^1.17.0" - } - }, - "@rollup/pluginutils": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-3.1.0.tgz", - "integrity": "sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==", - "dev": true, - "requires": { - "@types/estree": "0.0.39", - "estree-walker": "^1.0.1", - "picomatch": "^2.2.2" - }, - "dependencies": { - "estree-walker": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-1.0.1.tgz", - "integrity": "sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==", - "dev": true - } - } - }, "@semantic-release/changelog": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/@semantic-release/changelog/-/changelog-5.0.1.tgz", @@ -11375,12 +11229,6 @@ } } }, - "@types/estree": { - "version": "0.0.39", - "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz", - "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==", - "dev": true - }, "@types/is-windows": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@types/is-windows/-/is-windows-1.0.0.tgz", @@ -12769,12 +12617,6 @@ "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", "dev": true }, - "estree-walker": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz", - "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", - "dev": true - }, "esutils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", @@ -13284,14 +13126,6 @@ "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "dev": true }, - "fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "dev": true, - "optional": true, - "peer": true - }, "function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", @@ -13834,15 +13668,6 @@ "integrity": "sha512-zohwelOAur+5uXtk8O3GPQ1eAcu4ZX3UwxQhUlfFFMNpUd83gXgjbhJh6HmB6LUNV/ieOLQuDwJO3dWJosUeMw==", "dev": true }, - "is-reference": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.2.1.tgz", - "integrity": "sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==", - "dev": true, - "requires": { - "@types/estree": "*" - } - }, "is-regex": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.2.tgz", @@ -14155,15 +13980,6 @@ "yallist": "^4.0.0" } }, - "magic-string": { - "version": "0.25.7", - "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.7.tgz", - "integrity": "sha512-4CrMT5DOHTDk4HYDlzmwu4FVCcIYI8gauveasrdCu2IKIFOJ3f0v/8MDGJCDL9oD2ppz/Av1b0Nj345H9M+XIA==", - "dev": true, - "requires": { - "sourcemap-codec": "^1.4.4" - } - }, "make-dir": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", @@ -18031,16 +17847,6 @@ "glob": "^7.1.3" } }, - "rollup": { - "version": "2.44.0", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.44.0.tgz", - "integrity": "sha512-rGSF4pLwvuaH/x4nAS+zP6UNn5YUDWf/TeEU5IoXSZKBbKRNTCI3qMnYXKZgrC0D2KzS2baiOZt1OlqhMu5rnQ==", - "dev": true, - "peer": true, - "requires": { - "fsevents": "~2.3.1" - } - }, "run-async": { "version": "2.4.1", "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.4.1.tgz", @@ -18369,12 +18175,6 @@ "integrity": "sha512-cPiFOTLUKvJFIg4SKVScy4ilPPW6rFgMgfuZJPNoDuMs3nC1HbMUycBoJw77xFIp6z1UJQJOfx6C9GMH80DiTw==", "dev": true }, - "sourcemap-codec": { - "version": "1.4.8", - "resolved": "https://registry.npmjs.org/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz", - "integrity": "sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==", - "dev": true - }, "spawn-wrap": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/spawn-wrap/-/spawn-wrap-2.0.0.tgz", diff --git a/package.json b/package.json index 70d9c1287..6053b6e5d 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "1.0.2", "scripts": { "coverage": "npx c8 --reporter=html --require $TARGET node test/unit/$TARGET", - "build": "npx rollup --plugin commonjs lib/server/inline.mjs --file dist/inline.js --format cjs", + "build": "npx rollup lib/server/inline-channel.mjs --file dist/inline-channel.js --format cjs", "prettify": "npx prettier --write 'lib/server/**/*.mjs' 'lib/client/**/*.js' 'test/**/*.mjs' 'bin/*.mjs'", "commit": "npx cz", "lint": "npx eslint 'lib/client/**/*.js' 'lib/server/**/*.mjs' 'test/**/*.mjs' 'bin/*.mjs'", @@ -11,9 +11,10 @@ "deploy": "npx semantic-release" }, "files": [ - "dist/*.js", - "lib/**/*.{js,mjs}", - "bin/*.mjs" + "/home.js", + "/dist/*.js", + "/lib/**/*.{js,mjs}", + "/bin/*.mjs" ], "bin": { "appmap": "bin/agent.mjs" @@ -26,7 +27,6 @@ "yaml": "^1.10.0" }, "devDependencies": { - "@rollup/plugin-commonjs": "^18.0.0", "@semantic-release/changelog": "^5.0.1", "@semantic-release/git": "^9.0.0", "c8": "^7.6.0", diff --git a/test/unit/lib/client/es2015/node/setup.mjs b/test/unit/lib/client/es2015/node/setup.mjs index dfd5c2199..6d2baeb8c 100644 --- a/test/unit/lib/client/es2015/node/setup.mjs +++ b/test/unit/lib/client/es2015/node/setup.mjs @@ -36,13 +36,13 @@ Assert.deepEqual(global[TRACE_IDENTIFIER], [ env: emitter.env, pid: emitter.pid, engine: `node@${emitter.version}`, - feature: "TODO", - feature_group: "TODO", - labels: ["TODO"], - frameworks: ["TODO"], + feature: 'TODO', + feature_group: 'TODO', + labels: ['TODO'], + frameworks: ['TODO'], recording: { - defined_class: "TODO", - method_id: "TODO", + defined_class: 'TODO', + method_id: 'TODO', }, }, ], diff --git a/test/unit/lib/server/appmap.mjs b/test/unit/lib/server/appmap.mjs index 5ff14e162..b88ac996d 100644 --- a/test/unit/lib/server/appmap.mjs +++ b/test/unit/lib/server/appmap.mjs @@ -1,69 +1,72 @@ import { strict as Assert } from 'assert'; import * as FileSystem from 'fs'; -import { getDefaultConfig } from "../../../../lib/server/config.mjs"; +import { getDefaultConfig } from '../../../../lib/server/config.mjs'; import Appmap from '../../../../lib/server/appmap.mjs'; const appmap = new Appmap(); -appmap.instrument("source", "path1", "content"); -appmap.emit("event1"); -appmap.terminate("reason1"); +appmap.instrument('source', 'path1', 'content'); +appmap.emit('event1'); +appmap.terminate('reason1'); -appmap.initialize("recorder1", getDefaultConfig(), { +appmap.initialize('recorder1', getDefaultConfig(), { env: { - "APPMAP_OUTPUT_DIR": "tmp/appmap", - "APPMAP_MAP_NAME": "map-name" + APPMAP_OUTPUT_DIR: 'tmp/appmap', + APPMAP_MAP_NAME: 'map-name', }, - feature: "feature", - labels: ["label"], - frameworks: ["framework"], - feature_group: "feature-group", - recording: "recording", + feature: 'feature', + labels: ['label'], + frameworks: ['framework'], + feature_group: 'feature-group', + recording: 'recording', }); -appmap.initialize("recorder2", getDefaultConfig(), {env:{}}); -appmap.instrument("script", "path2", "({});"); -appmap.emit("event2"); -appmap.terminate("reason2"); +appmap.initialize('recorder2', getDefaultConfig(), { env: {} }); +appmap.instrument('script', 'path2', '({});'); +appmap.emit('event2'); +appmap.terminate('reason2'); -const json = JSON.parse(FileSystem.readFileSync("tmp/appmap/map-name.appmap.json", "utf8")); +const json = JSON.parse( + FileSystem.readFileSync('tmp/appmap/map-name.appmap.json', 'utf8'), +); -Assert.equal(json.metadata.git.repository, "https://github.com/applandinc/appmap-agent-js"); +Assert.equal( + json.metadata.git.repository, + 'https://github.com/applandinc/appmap-agent-js', +); delete json.metadata.git; -Assert.deepEqual( - json, - { - version: '1.4', - metadata: { - name: 'unknown-map-name', - labels: [ 'label' ], - app: 'unknown-app-name', - feature: 'feature', - feature_group: 'feature-group', - language: { name: 'javascript', version: '2015' }, - frameworks: [ 'framework' ], - client: { - name: '@appland/appmap-agent-js', - url: 'https://github.com/applandinc/appmap-agent-js.git', - version: '1.0.2' - }, - recorder: { name: 'recorder1' }, - recording: 'recording', +Assert.deepEqual(json, { + version: '1.4', + metadata: { + name: 'unknown-map-name', + labels: ['label'], + app: 'unknown-app-name', + feature: 'feature', + feature_group: 'feature-group', + language: { name: 'javascript', version: '2015' }, + frameworks: ['framework'], + client: { + name: '@appland/appmap-agent-js', + url: 'https://github.com/applandinc/appmap-agent-js.git', + version: '1.0.2', }, - classMap: [ - { - type: 'package', - name: 'path2', - childeren: [ { type: 'class', name: '§none', childeren: [] } ] - } - ], - events: [ 'event2' ] + recorder: { name: 'recorder1' }, + recording: 'recording', }, -); - + classMap: [ + { + type: 'package', + name: 'path2', + childeren: [{ type: 'class', name: '§none', childeren: [] }], + }, + ], + events: ['event2'], +}); -appmap.initialize("recorder3", getDefaultConfig(), {env:{ - APPMAP_OUTPUT_DIR: "foo/bar/qux", -}}); -appmap.terminate("reason3"); +appmap.initialize('recorder3', getDefaultConfig(), { + env: { + APPMAP_OUTPUT_DIR: 'foo/bar/qux', + }, +}); +appmap.terminate('reason3'); diff --git a/test/unit/lib/server/config.mjs b/test/unit/lib/server/config.mjs index fae6d4a5f..f9a0c5c19 100644 --- a/test/unit/lib/server/config.mjs +++ b/test/unit/lib/server/config.mjs @@ -6,37 +6,38 @@ import { getDefaultConfig } from '../../../../lib/server/config.mjs'; const config = getDefaultConfig(); -config.extendWithPath("/foo"); -config.extendWithPath("/foo.json"); -config.extendWithPath("/foo.yml"); +config.extendWithPath('/foo'); +config.extendWithPath('/foo.json'); +config.extendWithPath('/foo.yml'); config.extendWithJson(123); -config.extendWithJson({extend:123}); -config.extendWithJson({extend:"/foo"}); -config.extendWithEnv({APPMAP_CONFIG:"/foo"}); +config.extendWithJson({ extend: 123 }); +config.extendWithJson({ extend: '/foo' }); +config.extendWithEnv({ APPMAP_CONFIG: '/foo' }); -writeFileSync("tmp/test/conf.yml", "name: foo", "utf8"); -Assert.equal(config.extendWithPath("tmp/test/conf.yml").getAppName(), "foo"); +writeFileSync('tmp/test/conf.yml', 'name: foo', 'utf8'); +Assert.equal(config.extendWithPath('tmp/test/conf.yml').getAppName(), 'foo'); -writeFileSync("tmp/test/conf.json", "@foo", "utf8"); -config.extendWithPath("tmp/test/conf.json"); +writeFileSync('tmp/test/conf.json', '@foo', 'utf8'); +config.extendWithPath('tmp/test/conf.json'); -const makeMakeTest = (method) => (kind, key) => (value) => config[`extendWith${kind}`]({[key]: value})[method](); +const makeMakeTest = (method) => (kind, key) => (value) => + config[`extendWith${kind}`]({ [key]: value })[method](); // simple strings // [ - ["getGitDir", "APPMAP_GIT_DIR", "git-dir", "."], - ["getOutputDir", "APPMAP_OUTPUT_DIR", "output-dir", "tmp/appmap"], - ["getAppName", "APPMAP_APP_NAME", "name", "unknown-app-name"], - ["getMapName", "APPMAP_MAP_NAME", "map-name", "unknown-map-name"], + ['getGitDir', 'APPMAP_GIT_DIR', 'git-dir', '.'], + ['getOutputDir', 'APPMAP_OUTPUT_DIR', 'output-dir', 'tmp/appmap'], + ['getAppName', 'APPMAP_APP_NAME', 'name', 'unknown-app-name'], + ['getMapName', 'APPMAP_MAP_NAME', 'map-name', 'unknown-map-name'], ].forEach(([method, key1, key2, def]) => { const makeTest = makeMakeTest(method); { - const test = makeTest("Env", key1); - Assert.equal(test("foo"), "foo"); + const test = makeTest('Env', key1); + Assert.equal(test('foo'), 'foo'); } { - const test = makeTest("Json", key2); - Assert.equal(test("foo"), "foo"); + const test = makeTest('Json', key2); + Assert.equal(test('foo'), 'foo'); Assert.equal(test(123), def); } }); @@ -44,81 +45,84 @@ const makeMakeTest = (method) => (kind, key) => (value) => config[`extendWith${k // isEnabled // { const def = false; - const makeTest = makeMakeTest("isEnabled"); + const makeTest = makeMakeTest('isEnabled'); { - const test = makeTest("Env", "APPMAP"); - Assert.equal(test("TruE"), true); - Assert.equal(test("FalsE"), false); - Assert.equal(test("foo"), def); + const test = makeTest('Env', 'APPMAP'); + Assert.equal(test('TruE'), true); + Assert.equal(test('FalsE'), false); + Assert.equal(test('foo'), def); } { - const test = makeTest("Json", "enabled"); + const test = makeTest('Json', 'enabled'); Assert.equal(test(true), true); Assert.equal(test(false), false); - Assert.equal(test("foo"), def); + Assert.equal(test('foo'), def); } } // getEscapePrefix // { - const def = "APPMAP"; - const makeTest = makeMakeTest("getEscapePrefix"); + const def = 'APPMAP'; + const makeTest = makeMakeTest('getEscapePrefix'); { - const test = makeTest("Env", "APPMAP_ESCAPE_PREFIX"); - Assert.equal(test("foo"), "foo"); - Assert.equal(test("@bar"), def); + const test = makeTest('Env', 'APPMAP_ESCAPE_PREFIX'); + Assert.equal(test('foo'), 'foo'); + Assert.equal(test('@bar'), def); } { - const test = makeTest("Json", "escape-prefix"); - Assert.equal(test("foo"), "foo"); - Assert.equal(test("@bar"), def); + const test = makeTest('Json', 'escape-prefix'); + Assert.equal(test('foo'), 'foo'); + Assert.equal(test('@bar'), def); Assert.equal(test(123), def); } } // language_version // { - const def = "2015"; - const makeTest = makeMakeTest("getLanguageVersion"); + const def = '2015'; + const makeTest = makeMakeTest('getLanguageVersion'); { - const test = makeTest("Env", "APPMAP_LANGUAGE_VERSION"); - Assert.equal(test("5"), "5"); - Assert.equal(test("foo"), def); + const test = makeTest('Env', 'APPMAP_LANGUAGE_VERSION'); + Assert.equal(test('5'), '5'); + Assert.equal(test('foo'), def); } { - const test = makeTest("Json", "language-version"); - Assert.equal(test("5"), "5"); - Assert.equal(test("foo"), def); + const test = makeTest('Json', 'language-version'); + Assert.equal(test('5'), '5'); + Assert.equal(test('foo'), def); Assert.equal(test(5), def); } } // getPackages // { - const makeTest = makeMakeTest("getPackages"); + const makeTest = makeMakeTest('getPackages'); { - const test = makeTest("Env", "APPMAP_PACKAGES"); - Assert.deepEqual(test(" foo , bar "), [{name:"foo"}, {name:"bar"}]); + const test = makeTest('Env', 'APPMAP_PACKAGES'); + Assert.deepEqual(test(' foo , bar '), [{ name: 'foo' }, { name: 'bar' }]); } { - const test = makeTest("Json", "packages"); - Assert.deepEqual(test([{name:"foo"}, "bar"]), [{name:"foo"}, {name:"bar"}]); + const test = makeTest('Json', 'packages'); + Assert.deepEqual(test([{ name: 'foo' }, 'bar']), [ + { name: 'foo' }, + { name: 'bar' }, + ]); Assert.deepEqual(test(123), []); - Assert.deepEqual(test([456, {}, {name:789}, "qux"]), [{name:"qux"}]); + Assert.deepEqual(test([456, {}, { name: 789 }, 'qux']), [{ name: 'qux' }]); } } // getExclusions // { - const makeTest = makeMakeTest("getExclusions"); + const makeTest = makeMakeTest('getExclusions'); { - const test = makeTest("Env", "APPMAP_EXCLUDE"); - Assert.deepEqual(test(" foo , bar "), ["foo", "bar"]); + const test = makeTest('Env', 'APPMAP_EXCLUDE'); + Assert.deepEqual(test(' foo , bar '), ['foo', 'bar']); } { - const test = makeTest("Json", "exclude"); - Assert.deepEqual(test(["foo", "bar"]), ["foo", "bar"]); + const test = makeTest('Json', 'exclude'); + Assert.deepEqual(test(['foo', 'bar']), ['foo', 'bar']); Assert.deepEqual(test(123), []); - Assert.deepEqual(test([456, "qux"]), ["qux"]); + Assert.deepEqual(test([456, 'qux']), ['qux']); } } diff --git a/test/unit/lib/server/inline-channel.mjs b/test/unit/lib/server/inline-channel.mjs new file mode 100644 index 000000000..0b1573f82 --- /dev/null +++ b/test/unit/lib/server/inline-channel.mjs @@ -0,0 +1,46 @@ +import { strict as Assert } from 'assert'; +import * as FileSystem from 'fs'; +import makeChannel from '../../../../lib/server/inline-channel.mjs'; + +const channel = makeChannel(); + +channel.initialize({ + env: { + APPMAP_OUTPUT_DIR: 'tmp/appmap', + APPMAP_MAP_NAME: 'foo', + }, +}); + +Assert.equal( + channel.instrumentScript(`filename.js`, `const o1 = {};`), + `const o1 = {};`, +); + +channel.instrumentModule(`filename.mjs`, `const o2 = {};`, { + resolve: (...args) => { + Assert.deepEqual(args, [`const o2 = {};`]); + }, + reject: () => { + Assert.fail(); + }, +}); + +channel.instrumentModule(`filename.mjs`, `@INVALID_JS@`, { + resolve: (...args) => { + Assert.fail(); + }, + reject: (...args) => { + Assert.equal(args.length, 1); + Assert.ok(args[0] instanceof Error); + }, +}); + +channel.emit('event'); + +channel.terminate('reason'); + +const json = JSON.parse( + FileSystem.readFileSync(`tmp/appmap/foo.appmap.json`, 'utf8'), +); + +Assert.deepEqual(json.events, ['event']); diff --git a/test/unit/lib/server/inline-main.mjs b/test/unit/lib/server/inline-main.mjs new file mode 100644 index 000000000..673d3296f --- /dev/null +++ b/test/unit/lib/server/inline-main.mjs @@ -0,0 +1,47 @@ + +import * as FileSystem from "fs"; +import { strict as Assert } from 'assert'; +import main from '../../../../lib/server/inline-main.mjs'; + +// const counter = 0; + +// const onError = (error) => { +// console.log(error.message); +// // counter += 1; +// }; + +const path = "tmp/test/foo.js"; + +FileSystem.writeFileSync( + path, + "({});", + "utf8" +); + +// FileSystem.writeFileSync( +// "tmp/test/native.mjs", +// "({});" +// ); + +main({ + "output-dir": "tmp/appmap/", + "app-name": "foo", + "map-name": "bar", + _: [path] +}); + +main({ + cjs: true, + _: [path], +}); + +main({ + mjs: true, + _: [path], +}); + +main({ + cjs: true, + mjs: true, + _: [path], +}); diff --git a/test/unit/lib/server/inline.mjs b/test/unit/lib/server/inline.mjs deleted file mode 100644 index 7372faec3..000000000 --- a/test/unit/lib/server/inline.mjs +++ /dev/null @@ -1,105 +0,0 @@ -import { strict as Assert } from 'assert'; -import * as FileSystem from 'fs'; -import makeChannel from '../../../../lib/server/inline.mjs'; - -const channel = makeChannel(); - -channel.initialize({ - env: { - APPMAP_OUTPUT_DIR: 'tmp/appmap', - APPMAP_MAP_NAME: 'foo', - } -}); - -Assert.equal( - channel.instrumentScript(`filename.js`, `const o1 = {};`), - `const o1 = {};`, -); - -channel.instrumentModule(`filename.mjs`, `const o2 = {};`, { - resolve: (...args) => { - Assert.deepEqual(args, [`const o2 = {};`]); - }, - reject: () => { - Assert.fail(); - }, -}); - -channel.instrumentModule(`filename.mjs`, `@INVALID_JS@`, { - resolve: (...args) => { - Assert.fail(); - }, - reject: (...args) => { - Assert.equal(args.length, 1); - Assert.ok(args[0] instanceof Error); - }, -}); - -channel.emit('event'); - -channel.terminate('reason'); - -const json = JSON.parse( - FileSystem.readFileSync(`tmp/appmap/foo.appmap.json`, 'utf8'), -); - -Assert.deepEqual(json.events, ["event"]); - -// Assert.deepEqual( -// main({ -// _: [path, 'foo', 'bar'], -// }), -// ['node', path, 'foo', 'bar', 'qux'], -// ); -// -// Assert.deepEqual( -// main({ -// channel: 'foo', -// }), -// undefined, -// ); -// -// -// -// -// import { strict as Assert } from 'assert'; -// import { load } from '../../../__fixture__.mjs'; -// -// load('src/es2015/node/send/local.js'); -// -// const trace = []; -// -// global.APPMAP_GLOBAL_APPMAP_OBJECT = { -// setEngine(...args) { -// Assert.equal(this, global.APPMAP_GLOBAL_APPMAP_OBJECT); -// trace.push(['engine', ...args]); -// }, -// addEvent(...args) { -// Assert.equal(this, global.APPMAP_GLOBAL_APPMAP_OBJECT); -// trace.push(['event', ...args]); -// }, -// archive(...args) { -// Assert.equal(this, global.APPMAP_GLOBAL_APPMAP_OBJECT); -// trace.push(['archive', ...args]); -// }, -// }; -// -// Assert.equal( -// APPMAP_GLOBAL_SEND('engine', { -// name: 'engine-name', -// version: 'engine-version', -// }), -// true, -// ); -// -// Assert.equal(APPMAP_GLOBAL_SEND('event', 'event-data'), true); -// -// Assert.equal(APPMAP_GLOBAL_SEND('archive', 'archive-data'), true); -// -// Assert.equal(APPMAP_GLOBAL_SEND('foo', 'bar'), false); -// -// Assert.deepEqual(trace, [ -// ['engine', 'engine-name', 'engine-version'], -// ['event', 'event-data'], -// ['archive', 'archive-data'], -// ]); diff --git a/test/unit/lib/server/logger.mjs b/test/unit/lib/server/logger.mjs index 62daf3b56..ab762fca0 100644 --- a/test/unit/lib/server/logger.mjs +++ b/test/unit/lib/server/logger.mjs @@ -1,6 +1,6 @@ import { strict as Assert } from 'assert'; import logger from '../../../../lib/server/logger.mjs'; -logger.error("error"); -logger.warning("warning"); -logger.info("info"); +logger.error('error'); +logger.warning('warning'); +logger.info('info'); diff --git a/test/unit/ordering.mjs b/test/unit/ordering.mjs index c61413bed..57d0a7dfc 100644 --- a/test/unit/ordering.mjs +++ b/test/unit/ordering.mjs @@ -1,30 +1,31 @@ export const server = [ - 'logger', - 'config', - 'git', - 'namespace', - 'file', - 'instrument/location', - 'instrument/visit', - 'instrument/visit-class', - 'instrument/visit-closure', - 'instrument/visit-expression', - 'instrument/visit-identifier', - 'instrument/visit-pattern', - 'instrument/visit-program', - 'instrument/visit-statement', - 'instrument/index', - 'appmap', - 'inline', + // 'logger', + // 'config', + // 'git', + // 'namespace', + // 'file', + // 'instrument/location', + // 'instrument/visit', + // 'instrument/visit-class', + // 'instrument/visit-closure', + // 'instrument/visit-expression', + // 'instrument/visit-identifier', + // 'instrument/visit-pattern', + // 'instrument/visit-program', + // 'instrument/visit-statement', + // 'instrument/index', + // 'appmap', + // 'inline-channel', + 'inline-main', ]; export const client = [ - 'es2015/script', - 'es2015/node/channel/test', - 'es2015/node/setup', - 'es2015/node/hook-cjs', - 'es2015/node/hook-esm', - 'es2015/node/main-cjs', - 'es2015/node/main-esm', - 'es2015/node/main-both', + // 'es2015/script', + // 'es2015/node/channel/test', + // 'es2015/node/setup', + // 'es2015/node/hook-cjs', + // 'es2015/node/hook-esm', + // 'es2015/node/main-cjs', + // 'es2015/node/main-esm', + // 'es2015/node/main-both', ];