Skip to content

Commit

Permalink
refactor: use spaces for indentation (#126)
Browse files Browse the repository at this point in the history
* chore: move over to spaces in editorconfig

* chore: move over to spaces in eslint

* chore: reformat all files with spaces

* chore: fix wrong editorconfig setting

* chore: rebuild files
  • Loading branch information
byCedric authored Nov 16, 2021
1 parent 1cfa7bb commit ff2ff0f
Show file tree
Hide file tree
Showing 13 changed files with 913 additions and 922 deletions.
10 changes: 1 addition & 9 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@ root = true
[*]
charset = utf-8
end_of_line = lf
indent_style = tab
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
indent_style = space
trim_trailing_whitespace = false

[*.yml]
indent_size = 2
indent_style = space
insert_final_newline = true
27 changes: 13 additions & 14 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
module.exports = {
ignorePatterns: ['/build/**', 'node_modules/**'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'jest', 'prettier'],
env: {
es6: true,
'jest/globals': true,
node: true,
},
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
rules: {
'@typescript-eslint/explicit-member-accessibility': ['error', { accessibility: 'no-public' }],
'@typescript-eslint/indent': ['error', 'tab'],
'prettier/prettier': 'error',
},
ignorePatterns: ['/build/**', 'node_modules/**'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'jest', 'prettier'],
env: {
es6: true,
'jest/globals': true,
node: true,
},
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
rules: {
'@typescript-eslint/explicit-member-accessibility': ['error', { accessibility: 'no-public' }],
'prettier/prettier': 'error',
},
};
18 changes: 9 additions & 9 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module.exports = {
verbose: true,
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
testRunner: 'jest-circus/runner',
transform: {
'^.+\\.ts$': 'ts-jest',
},
verbose: true,
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
testRunner: 'jest-circus/runner',
transform: {
'^.+\\.ts$': 'ts-jest',
},
};
42 changes: 21 additions & 21 deletions ncc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,41 @@ const BUILD_DIR = path.resolve(__dirname, 'build');
const ACTION_DIR = path.resolve(__dirname, 'src/actions');

const options = {
cache: false,
minify: true,
sourceMap: true,
quiet: true,
cache: false,
minify: true,
sourceMap: true,
quiet: true,
};

async function write(file, content) {
await fs.promises.writeFile(file, content, { encoding: 'utf-8' });
await fs.promises.writeFile(file, content, { encoding: 'utf-8' });
}

async function build(file) {
const { code, map, assets } = await ncc(file, options);
const name = path.basename(file, path.extname(file));
const dir = path.resolve(BUILD_DIR, name);
const { code, map, assets } = await ncc(file, options);
const name = path.basename(file, path.extname(file));
const dir = path.resolve(BUILD_DIR, name);

await fs.promises.mkdir(dir, { recursive: true });
await fs.promises.mkdir(dir, { recursive: true });

for (const asset in assets) {
await fs.promises.mkdir(path.join(dir, path.dirname(asset)), { recursive: true });
await write(path.join(dir, asset), assets[asset].source);
}
for (const asset in assets) {
await fs.promises.mkdir(path.join(dir, path.dirname(asset)), { recursive: true });
await write(path.join(dir, asset), assets[asset].source);
}

await write(path.join(dir, 'index.js'), code.replace(/\r\n/g, '\n'));
await write(path.join(dir, 'index.map.js'), map.replace(/\r\n/g, '\n'));
await write(path.join(dir, 'index.js'), code.replace(/\r\n/g, '\n'));
await write(path.join(dir, 'index.map.js'), map.replace(/\r\n/g, '\n'));

console.log(`✓ ${path.relative(__dirname, file)}`);
console.log(`✓ ${path.relative(__dirname, file)}`);
}

async function main() {
const actionPath = path.resolve(__dirname, './src/actions');
const actionFiles = (await fs.promises.readdir(actionPath, { withFileTypes: true }))
.filter(entity => entity.isFile())
.map(entity => path.join(ACTION_DIR, entity.name));
const actionPath = path.resolve(__dirname, './src/actions');
const actionFiles = (await fs.promises.readdir(actionPath, { withFileTypes: true }))
.filter(entity => entity.isFile())
.map(entity => path.join(ACTION_DIR, entity.name));

return Promise.all(actionFiles.map(build));
return Promise.all(actionFiles.map(build));
}

main();
94 changes: 47 additions & 47 deletions src/actions/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,54 @@ import * as tools from '../tools';
tools.performAction(setupAction);

export async function setupAction(): Promise<void> {
const expoVersion = await installCli('expo-cli');
const easVersion = await installCli('eas-cli');

await group('Checking current authenticated account', () =>
tools.maybeAuthenticate({
cli: expoVersion ? 'expo-cli' : easVersion ? 'eas-cli' : undefined,
token: getInput('token') || undefined,
username: getInput('username') || undefined,
password: getInput('password') || undefined,
})
);

if (tools.getBoolean(getInput('patch-watchers'), true)) {
await group('Patching system watchers for the `ENOSPC` error', () => tools.maybePatchWatchers());
}
const expoVersion = await installCli('expo-cli');
const easVersion = await installCli('eas-cli');

await group('Checking current authenticated account', () =>
tools.maybeAuthenticate({
cli: expoVersion ? 'expo-cli' : easVersion ? 'eas-cli' : undefined,
token: getInput('token') || undefined,
username: getInput('username') || undefined,
password: getInput('password') || undefined,
})
);

if (tools.getBoolean(getInput('patch-watchers'), true)) {
await group('Patching system watchers for the `ENOSPC` error', () => tools.maybePatchWatchers());
}
}

async function installCli(name: tools.PackageName): Promise<string | void> {
const shortName = tools.getBinaryName(name);
const inputVersion = getInput(`${shortName}-version`);
const packager = getInput('packager') || 'yarn';

if (!inputVersion) {
return info(`Skipping installation of ${name}, \`${shortName}-version\` not provided.`);
}

const version = await tools.resolveVersion(name, inputVersion);
const cache = tools.getBoolean(getInput(`${shortName}-cache`), false);

try {
const path = await group(
cache
? `Installing ${name} (${version}) from cache or with ${packager}`
: `Installing ${name} (${version}) with ${packager}`,
() =>
install({
packager,
version,
cache,
package: name,
cacheKey: getInput(`${shortName}-cache-key`) || undefined,
})
);

addPath(path);
} catch (error) {
tools.handleError(name, error);
}

return version;
const shortName = tools.getBinaryName(name);
const inputVersion = getInput(`${shortName}-version`);
const packager = getInput('packager') || 'yarn';

if (!inputVersion) {
return info(`Skipping installation of ${name}, \`${shortName}-version\` not provided.`);
}

const version = await tools.resolveVersion(name, inputVersion);
const cache = tools.getBoolean(getInput(`${shortName}-cache`), false);

try {
const path = await group(
cache
? `Installing ${name} (${version}) from cache or with ${packager}`
: `Installing ${name} (${version}) with ${packager}`,
() =>
install({
packager,
version,
cache,
package: name,
cacheKey: getInput(`${shortName}-cache-key`) || undefined,
})
);

addPath(path);
} catch (error) {
tools.handleError(name, error);
}

return version;
}
66 changes: 33 additions & 33 deletions src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type CacheConfig = Omit<InstallConfig, 'cache'>;
* @see https://github.com/actions/toolkit/issues/47
*/
export async function fromLocalCache(config: CacheConfig): Promise<string | undefined> {
return toolCache.find(config.package, config.version);
return toolCache.find(config.package, config.version);
}

/**
Expand All @@ -25,52 +25,52 @@ export async function fromLocalCache(config: CacheConfig): Promise<string | unde
* @see https://github.com/actions/toolkit/issues/47
*/
export async function toLocalCache(root: string, config: CacheConfig): Promise<string> {
return toolCache.cacheDir(root, config.package, config.version);
return toolCache.cacheDir(root, config.package, config.version);
}

/**
* Download the remotely stored `expo-cli` from cache, if any.
* Note, this cache is shared between jobs.
*/
export async function fromRemoteCache(config: CacheConfig): Promise<string | undefined> {
// see: https://github.com/actions/toolkit/blob/8a4134761f09d0d97fb15f297705fd8644fef920/packages/tool-cache/src/tool-cache.ts#L401
const target = path.join(process.env['RUNNER_TOOL_CACHE'] || '', config.package, config.version, os.arch());
const cacheKey = config.cacheKey || getRemoteKey(config);
// see: https://github.com/actions/toolkit/blob/8a4134761f09d0d97fb15f297705fd8644fef920/packages/tool-cache/src/tool-cache.ts#L401
const target = path.join(process.env['RUNNER_TOOL_CACHE'] || '', config.package, config.version, os.arch());
const cacheKey = config.cacheKey || getRemoteKey(config);

try {
// When running with nektos/act, or other custom environments, the cache might not be set up.
const hit = await restoreCache([target], cacheKey);
if (hit) {
return target;
}
} catch (error) {
if (!handleRemoteCacheError(error)) {
throw error;
}
}
try {
// When running with nektos/act, or other custom environments, the cache might not be set up.
const hit = await restoreCache([target], cacheKey);
if (hit) {
return target;
}
} catch (error) {
if (!handleRemoteCacheError(error)) {
throw error;
}
}
}

/**
* Store the root of `expo-cli` in the remote cache, for future reuse.
* Note, this cache is shared between jobs.
*/
export async function toRemoteCache(source: string, config: CacheConfig): Promise<void> {
const cacheKey = config.cacheKey || getRemoteKey(config);
const cacheKey = config.cacheKey || getRemoteKey(config);

try {
await saveCache([source], cacheKey);
} catch (error) {
if (!handleRemoteCacheError(error)) {
throw error;
}
}
try {
await saveCache([source], cacheKey);
} catch (error) {
if (!handleRemoteCacheError(error)) {
throw error;
}
}
}

/**
* Get the cache key to use when (re)storing the Expo CLI from remote cache.
*/
function getRemoteKey(config: Omit<CacheConfig, 'cacheKey'>): string {
return `${config.package}-${process.platform}-${os.arch()}-${config.packager}-${config.version}`;
return `${config.package}-${process.platform}-${os.arch()}-${config.packager}-${config.version}`;
}

/**
Expand All @@ -81,14 +81,14 @@ function getRemoteKey(config: Omit<CacheConfig, 'cacheKey'>): string {
* @returns If the error was handled properly.
*/
function handleRemoteCacheError(error: Error): boolean {
const isReserveCacheError = error instanceof ReserveCacheError;
const isCacheUnavailable = error.message.toLowerCase().includes('cache service url not found');
const isReserveCacheError = error instanceof ReserveCacheError;
const isCacheUnavailable = error.message.toLowerCase().includes('cache service url not found');

if (isReserveCacheError || isCacheUnavailable) {
core.warning('Skipping remote cache storage, encountered error:');
core.warning(error.message);
return true;
}
if (isReserveCacheError || isCacheUnavailable) {
core.warning('Skipping remote cache storage, encountered error:');
core.warning(error.message);
return true;
}

return false;
return false;
}
Loading

0 comments on commit ff2ff0f

Please sign in to comment.