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

Fix wrong imports #13601

Merged
merged 1 commit into from
Mar 4, 2019
Merged

Fix wrong imports #13601

merged 1 commit into from
Mar 4, 2019

Conversation

rodrigok
Copy link
Member

@rodrigok rodrigok commented Mar 2, 2019

Problem found when testing #13598 and tying to send an audio.

I've created a script to check all imports:

const fs = require('fs');
const glob = require('glob');

const packagesToMove = {
	'rocketchat:cors': 'rocketchat-cors',
	'rocketchat:sms': 'rocketchat-sms',
	'rocketchat:2fa': 'rocketchat-2fa',
	'rocketchat:accounts': 'rocketchat-accounts',
	'rocketchat:analytics': 'rocketchat-analytics',
	'rocketchat:api': 'rocketchat-api',
	'rocketchat:assets': 'rocketchat-assets',
	'rocketchat:authorization': 'rocketchat-authorization',
	'rocketchat:autolinker': 'rocketchat-autolinker',
	'rocketchat:autotranslate': 'rocketchat-autotranslate',
	'rocketchat:bot-helpers': 'rocketchat-bot-helpers',
	'rocketchat:cas': 'rocketchat-cas',
	'rocketchat:channel-settings': 'rocketchat-channel-settings',
	'rocketchat:channel-settings-mail-messages': 'rocketchat-channel-settings-mail-messages',
	'rocketchat:cloud': 'rocketchat-cloud',
	'rocketchat:colors': 'rocketchat-colors',
	'rocketchat:crowd': 'rocketchat-crowd',
	'rocketchat:custom-oauth': 'rocketchat-custom-oauth',
	'rocketchat:custom-sounds': 'rocketchat-custom-sounds',
	'rocketchat:dolphin': 'rocketchat-dolphin',
	'rocketchat:drupal': 'rocketchat-drupal',
	'rocketchat:emoji': 'rocketchat-emoji',
	'rocketchat:emoji-custom': 'rocketchat-emoji-custom',
	'rocketchat:emoji-emojione': 'rocketchat-emoji-emojione',
	'rocketchat:error-handler': 'rocketchat-error-handler',
	'rocketchat:favico': 'rocketchat-favico',
	'rocketchat:file': 'rocketchat-file',
	'rocketchat:file-upload': 'rocketchat-file-upload',
	'rocketchat:github-enterprise': 'rocketchat-github-enterprise',
	'rocketchat:gitlab': 'rocketchat-gitlab',
	'rocketchat:google-vision': 'rocketchat-google-vision',
	'rocketchat:grant': 'rocketchat-grant',
	'rocketchat:grant-facebook': 'rocketchat-grant-facebook',
	'rocketchat:grant-github': 'rocketchat-grant-github',
	'rocketchat:grant-google': 'rocketchat-grant-google',
	'rocketchat:graphql': 'rocketchat-graphql',
	'rocketchat:highlight-words': 'rocketchat-highlight-words',
	'rocketchat:iframe-login': 'rocketchat-iframe-login',
	'rocketchat:importer': 'rocketchat-importer',
	'rocketchat:importer-csv': 'rocketchat-importer-csv',
	'rocketchat:importer-hipchat': 'rocketchat-importer-hipchat',
	'rocketchat:importer-hipchat-enterprise': 'rocketchat-importer-hipchat-enterprise',
	'rocketchat:importer-slack': 'rocketchat-importer-slack',
	'rocketchat:importer-slack-users': 'rocketchat-importer-slack-users',
	'rocketchat:integrations': 'rocketchat-integrations',
	'rocketchat:irc': 'rocketchat-irc',
	'rocketchat:issuelinks': 'rocketchat-issuelinks',
	'rocketchat:katex': 'rocketchat-katex',
	'rocketchat:ldap': 'rocketchat-ldap',
	'rocketchat:lib': 'rocketchat-lib',
	'rocketchat:livestream': 'rocketchat-livestream',
	'rocketchat:logger': 'rocketchat-logger',
	'rocketchat:login-token': 'rocketchat-token-login',
	'rocketchat:mailer': 'rocketchat-mailer',
	'rocketchat:mapview': 'rocketchat-mapview',
	'rocketchat:markdown': 'rocketchat-markdown',
	'rocketchat:mentions': 'rocketchat-mentions',
	'rocketchat:mentions-flextab': 'rocketchat-mentions-flextab',
	'rocketchat:message-action': 'rocketchat-message-action',
	'rocketchat:message-attachments': 'rocketchat-message-attachments',
	'rocketchat:message-mark-as-unread': 'rocketchat-message-mark-as-unread',
	'rocketchat:message-pin': 'rocketchat-message-pin',
	'rocketchat:message-snippet': 'rocketchat-message-snippet',
	'rocketchat:message-star': 'rocketchat-message-star',
	'rocketchat:migrations': 'rocketchat-migrations',
	'rocketchat:oauth2-server-config': 'rocketchat-oauth2-server-config',
	'rocketchat:oembed': 'rocketchat-oembed',
	'rocketchat:otr': 'rocketchat-otr',
	'rocketchat:push-notifications': 'rocketchat-push-notifications',
	'rocketchat:retention-policy': 'rocketchat-retention-policy',
	'rocketchat:apps': 'rocketchat-apps',
	'rocketchat:sandstorm': 'rocketchat-sandstorm',
	'rocketchat:setup-wizard': 'rocketchat-setup-wizard',
	'rocketchat:slackbridge': 'rocketchat-slackbridge',
	'rocketchat:slashcommands-archive': 'rocketchat-slashcommands-archiveroom',
	'rocketchat:slashcommands-asciiarts': 'rocketchat-slashcommand-asciiarts',
	'rocketchat:slashcommands-create': 'rocketchat-slashcommands-create',
	'rocketchat:slashcommands-help': 'rocketchat-slashcommands-help',
	'rocketchat:slashcommands-hide': 'rocketchat-slashcommands-hide',
	'rocketchat:slashcommands-invite': 'rocketchat-slashcommands-invite',
	'rocketchat:slashcommands-invite-all': 'rocketchat-slashcommands-inviteall',
	'rocketchat:slashcommands-join': 'rocketchat-slashcommands-join',
	'rocketchat:slashcommands-kick': 'rocketchat-slashcommands-kick',
	'rocketchat:slashcommands-leave': 'rocketchat-slashcommands-leave',
	'rocketchat:slashcommands-me': 'rocketchat-slashcommands-me',
	'rocketchat:slashcommands-msg': 'rocketchat-slashcommands-msg',
	'rocketchat:slashcommands-mute': 'rocketchat-slashcommands-mute',
	'rocketchat:slashcommands-open': 'rocketchat-slashcommands-open',
	'rocketchat:slashcommands-topic': 'rocketchat-slashcommands-topic',
	'rocketchat:slashcommands-unarchive': 'rocketchat-slashcommands-unarchiveroom',
	'rocketchat:slider': 'rocketchat-slider',
	'rocketchat:smarsh-connector': 'rocketchat-smarsh-connector',
	'rocketchat:spotify': 'rocketchat-spotify',
	'rocketchat:statistics': 'rocketchat-statistics',
	'rocketchat:theme': 'rocketchat_theme',
	'rocketchat:tokenpass': 'rocketchat-tokenpass',
	'rocketchat:tooltip': 'rocketchat-tooltip',
	'rocketchat:ui': 'rocketchat-ui',
	'rocketchat:ui-account': 'rocketchat-ui-account',
	'rocketchat:ui-admin': 'rocketchat-ui-admin',
	'rocketchat:ui-clean-history': 'rocketchat-ui-clean-history',
	'rocketchat:ui-flextab': 'rocketchat-ui-flextab',
	'rocketchat:ui-login': 'rocketchat-ui-login',
	'rocketchat:ui-master': 'rocketchat-ui-master',
	'rocketchat:ui-message': 'rocketchat-ui-message',
	'rocketchat:ui-sidenav': 'rocketchat-ui-sidenav',
	'rocketchat:ui-vrecord': 'rocketchat-ui-vrecord',
	'rocketchat:user-data-download': 'rocketchat-user-data-download',
	'rocketchat:videobridge': 'rocketchat-videobridge',
	'rocketchat:webdav': 'rocketchat-webdav',
	'rocketchat:webrtc': 'rocketchat-webrtc',
	'rocketchat:wordpress': 'rocketchat-wordpress',
	'rocketchat:nrr': 'rocketchat-nrr',
	'steffo:meteor-accounts-saml': 'meteor-accounts-saml',
	'rocketchat:e2e': 'rocketchat-e2e',
	'rocketchat:blockstack': 'rocketchat-blockstack',
	'rocketchat:version-check': 'rocketchat-version-check',
	'rocketchat:search': 'rocketchat-search',
	'chatpal:search': 'chatpal-search',
	'rocketchat:lazy-load': 'rocketchat-lazy-load',
	'rocketchat:bigbluebutton': 'rocketchat-bigbluebutton',
	'rocketchat:mailmessages': 'rocketchat-mail-messages',
	'rocketchat:utils': 'rocketchat-utils',
	'rocketchat:settings': 'rocketchat-settings',
	'rocketchat:models': 'rocketchat-models',
	'rocketchat:metrics': 'rocketchat-metrics',
	'rocketchat:callbacks': 'rocketchat-callbacks',
	'rocketchat:notifications': 'rocketchat-notifications',
	'rocketchat:promises': 'rocketchat-promises',
	'rocketchat:ui-utils': 'rocketchat-ui-utils',
	'rocketchat:ui-cached-collection': 'rocketchat-ui-cached-collection',
	'rocketchat:action-links': 'rocketchat-action-links',
	'rocketchat:reactions': 'rocketchat-reactions',
};

function process(variables, name, filePath) {
	variables = variables.replace(/\sas\s\w+/g, '').replace(/[\s\t]/g, '').replace(/,$/, '').split(',');

	const folder = packagesToMove[name];
	if (!folder) {
		return;
	}

	let file = '';
	try {
		file += fs.readFileSync(`packages/${ folder }/client/index.js`).toString();
	} catch (error) {
		// ignore-lint
	}

	try {
		file += fs.readFileSync(`packages/${ folder }/server/index.js`).toString();
	} catch (error) {
		// ignore-lint
	}

	try {
		file += fs.readFileSync(`packages/${ folder }/client/lib/index.js`).toString();
	} catch (error) {
		// ignore-lint
	}

	try {
		file += fs.readFileSync(`packages/${ folder }/server/lib/index.js`).toString();
	} catch (error) {
		// ignore-lint
	}

	try {
		file += fs.readFileSync(`packages/${ folder }/server/functions/index.js`).toString();
	} catch (error) {
		// ignore-lint
	}

	for (const variable of variables) {
		if (!file.includes(variable)) {
			console.log(`Wrong import of ${ variable } at ${ filePath }`);
		}
	}
}

const files = glob.sync('@(packages|imports|client|lib|server)/**/*.js');
files.forEach((filePath) => {
	let file = fs.readFileSync(filePath).toString();

	if (file.match(/((from|import) 'meteor\/rocketchat)|(await import\('meteor\/rocketchat)/g)) {
		file = file.replace(/import \{\s([\w,\s]+)\s\}\s?from 'meteor\/(rocketchat.+)?'/g, (str, variables, name) => {
			process(variables, name, filePath);
		});

		file = file.replace(/\{\s([\w,\s]+)\s\}\s?=\s?(await import\()'meteor\/(rocketchat.+)?'/g, (str, variables, p1, name) => {
			process(variables, name, filePath);
		});
	}
});

@rodrigok rodrigok merged commit 5ec74ad into develop Mar 4, 2019
@rodrigok rodrigok deleted the fix/wrong-imports branch March 4, 2019 12:12
@rodrigok rodrigok mentioned this pull request Apr 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants