Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw error on multiple carmi instances only when trying to compile carmi #328

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion bin/carmi
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ const commandLineArgs = require('command-line-args');
const carmi = require('../index');
const path = require('path');
const fs = require('fs-extra');
const { enableCurrentLine } = require('../src/currentLine');
const {enableCurrentLine} = require('../src/currentLine');
const {isUpToDate, getDependenciesHashes, analyzeDependencies} = require('../src/analyze-dependencies');
const getCacheFilePath = require('../src/get-cache-file-path');
const wrapModule = require('../src/wrap-module');
const base64ArrayBuffer = require('../bytecode/base64-arraybuffer');
const {renameSync} = require('fs')
const {v4: uuidv4} = require('uuid');

const GLOBAL_TOKEN = '__$CARMI$__';

const CACHE_SCENARIOS = {
mtime: 'mtime',
gitHash: 'git-hash'
Expand Down Expand Up @@ -142,6 +144,12 @@ async function run() {
throw e;
}

if (global[GLOBAL_TOKEN] && global[GLOBAL_TOKEN].length > 1) {
throw new Error(
`require of multiple versions of Carmi is not supported previously loaded from:${global[GLOBAL_TOKEN]}`
);
}

code = carmi.compile(model, options);
}

Expand Down
8 changes: 3 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ const {getCurrentLine} = require('./src/currentLine');
const {destruct} = require('./src/utils/destruct');

const GLOBAL_TOKEN = '__$CARMI$__';
if (global[GLOBAL_TOKEN]) {
throw new Error(
`require of multiple versions of Carmi is not supported previously loaded from:${global[GLOBAL_TOKEN]}`
);
if (!global[GLOBAL_TOKEN]) {
global[GLOBAL_TOKEN] = []
}
global[GLOBAL_TOKEN] = getCurrentLine();
global[GLOBAL_TOKEN].push(getCurrentLine())
const {initProxyHandler} = require('./src/proxyHandler');
const expressionBuilder = require('./src/expressionBuilder');
const unwrapableProxy = require('./src/unwrapable-proxy');
Expand Down
Loading