You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
137 lines
4.6 KiB
137 lines
4.6 KiB
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.assertProjectHasExpoExtensionFilesAsync = assertProjectHasExpoExtensionFilesAsync;
|
|
function _chalk() {
|
|
const data = _interopRequireDefault(require("chalk"));
|
|
_chalk = function () {
|
|
return data;
|
|
};
|
|
return data;
|
|
}
|
|
function _commander() {
|
|
const data = _interopRequireDefault(require("commander"));
|
|
_commander = function () {
|
|
return data;
|
|
};
|
|
return data;
|
|
}
|
|
function _findYarnWorkspaceRoot() {
|
|
const data = _interopRequireDefault(require("find-yarn-workspace-root"));
|
|
_findYarnWorkspaceRoot = function () {
|
|
return data;
|
|
};
|
|
return data;
|
|
}
|
|
function _CommandError() {
|
|
const data = require("../../CommandError");
|
|
_CommandError = function () {
|
|
return data;
|
|
};
|
|
return data;
|
|
}
|
|
function _log() {
|
|
const data = _interopRequireDefault(require("../../log"));
|
|
_log = function () {
|
|
return data;
|
|
};
|
|
return data;
|
|
}
|
|
function _ora() {
|
|
const data = require("../../utils/ora");
|
|
_ora = function () {
|
|
return data;
|
|
};
|
|
return data;
|
|
}
|
|
function _prompts() {
|
|
const data = require("../../utils/prompts");
|
|
_prompts = function () {
|
|
return data;
|
|
};
|
|
return data;
|
|
}
|
|
function _glob() {
|
|
const data = require("./glob");
|
|
_glob = function () {
|
|
return data;
|
|
};
|
|
return data;
|
|
}
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
async function queryExpoExtensionFilesAsync(projectRoot, ignore) {
|
|
const results = await (0, _glob().wrapGlobWithTimeout)(() => (0, _glob().everyMatchAsync)('**/*.expo.@(js|jsx|ts|tsx)', {
|
|
absolute: true,
|
|
ignore,
|
|
cwd: projectRoot
|
|
}), 5000);
|
|
if (results === false) {
|
|
_log().default.warn('Failed to query all project files. Skipping `.expo.*` extension check...');
|
|
return [];
|
|
}
|
|
return results;
|
|
}
|
|
async function assertProjectHasExpoExtensionFilesAsync(projectRoot, checkNodeModules = false) {
|
|
if (checkNodeModules) {
|
|
await assertModulesHasExpoExtensionFilesAsync(projectRoot);
|
|
} else {
|
|
_log().default.time('assertProjectHasExpoExtensionFilesAsync');
|
|
const matches = await queryExpoExtensionFilesAsync(projectRoot, [`**/@(Carthage|Pods|node_modules|ts-declarations|.expo)/**`, '@(ios|android|web)/**']).catch(() => []);
|
|
_log().default.timeEnd('assertProjectHasExpoExtensionFilesAsync');
|
|
if (matches.length) {
|
|
await promptMatchesAsync(matches);
|
|
}
|
|
}
|
|
}
|
|
|
|
/** Wraps `findWorkspaceRoot` and guards against having an empty `package.json` file in an upper directory. */
|
|
function getWorkspaceRoot(projectRoot) {
|
|
try {
|
|
return (0, _findYarnWorkspaceRoot().default)(projectRoot);
|
|
} catch (error) {
|
|
if (error.message.includes('Unexpected end of JSON input')) {
|
|
return null;
|
|
}
|
|
throw error;
|
|
}
|
|
}
|
|
async function assertModulesHasExpoExtensionFilesAsync(projectRoot) {
|
|
const spinner = (0, _ora().ora)('Checking project for deprecated features, this may take a moment.').start();
|
|
const root = getWorkspaceRoot(projectRoot) || projectRoot;
|
|
_log().default.time('assertModulesHasExpoExtensionFilesAsync');
|
|
let matches = await queryExpoExtensionFilesAsync(root, [`**/@(Carthage|Pods|ts-declarations|.expo)/**`, '@(ios|android|web)/**']).catch(() => []);
|
|
_log().default.timeEnd('assertModulesHasExpoExtensionFilesAsync');
|
|
matches = matches.filter(value => {
|
|
if (value.includes('node_modules')) {
|
|
// Remove duplicate files from packages compiled with bob
|
|
return !value.match(/node_modules\/.*\/lib\/commonjs/g);
|
|
}
|
|
return true;
|
|
});
|
|
if (!matches.length) {
|
|
spinner.succeed('Validated project');
|
|
return;
|
|
} else {
|
|
spinner.fail('Found project files with deprecated features');
|
|
}
|
|
logMatchedFiles(matches);
|
|
}
|
|
function logMatchedFiles(matches) {
|
|
const hasNodeModules = matches.find(match => match.includes('node_modules/'));
|
|
_log().default.error(_chalk().default.red(`Project is using deprecated ${_chalk().default.bold`.expo.*`} file extensions.\nPlease refactor the following files${hasNodeModules ? ' and upgrade modules' : ''} accordingly:\n\n`) + _chalk().default.reset(matches.map(match => `- ${match}`).join('\n') + _chalk().default.dim(`\n\nDangerously disable this check with ${_chalk().default.bold(`EXPO_LEGACY_IMPORTS=1`)}\nLearn more: http://expo.fyi/expo-extension-migration\n`)));
|
|
}
|
|
async function promptMatchesAsync(matches) {
|
|
logMatchedFiles(matches);
|
|
|
|
// Skip in nonInteractive to give users a bypass
|
|
if (_commander().default.nonInteractive || (await (0, _prompts().confirmAsync)({
|
|
message: 'Would you like to continue anyways?',
|
|
initial: true
|
|
}))) {
|
|
return;
|
|
}
|
|
throw new (_CommandError().SilentError)();
|
|
}
|
|
//# sourceMappingURL=deprecatedExtensionWarnings.js.map
|