Skip to content

Commit

Permalink
attempt to fix semver@7
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Jan 23, 2020
1 parent dc8af26 commit f2bae06
Show file tree
Hide file tree
Showing 6 changed files with 4,000 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -30,6 +30,7 @@
"resolve": "^1.10.0",
"resolve-from": "^3.0.0",
"rollup-pluginutils": "^2.3.3",
"semver": "^7.1.1",
"socket.io-client": "^2.2.0",
"webpack": "^4.29.0",
"webpack-cli": "^3.2.1"
Expand Down
16 changes: 16 additions & 0 deletions src/utils/special-cases.js
Expand Up @@ -124,6 +124,22 @@ module.exports = function ({ id, code, pkgBase, ast, scope, magicString, emitAss
return { transformed: true };
}
}
} else if (id.endsWith('semver/index.js') || global._unit && id.includes('semver')) {
let transformed = false;
for (const statement of ast.body) {
if (statement.type === 'ExpressionStatement' &&
statement.expression.type === 'CallExpression' &&
statement.expression.callee.type === 'Identifier' &&
statement.expression.callee.name === 'lazyExport' &&
statement.expression.arguments.length >= 2 &&
statement.expression.arguments[1].type === 'Literal' &&
typeof statement.expression.arguments[1].value === 'string') {
const arg = statement.expression.arguments[1]
magicString.overwrite(arg.start, arg.end, `require.resolve(${JSON.stringify(arg.value)})`);
transformed = true;
}
}
return { transformed };
}
return { transformed: false };
};

0 comments on commit f2bae06

Please sign in to comment.