install-ember-testem 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/src/index.js CHANGED
@@ -1,5 +1,6 @@
1
- import { createOptions, updatePackageJson } from './steps/index.js';
1
+ import { createOptions, updateConfig, updatePackageJson, } from './steps/index.js';
2
2
  export function runCodemod(codemodOptions) {
3
3
  const options = createOptions(codemodOptions);
4
+ updateConfig(options);
4
5
  updatePackageJson(options);
5
6
  }
@@ -1,2 +1,3 @@
1
1
  export * from './create-options.js';
2
+ export * from './update-config.js';
2
3
  export * from './update-package-json.js';
@@ -0,0 +1,40 @@
1
+ import { readFileSync, rmSync, writeFileSync } from 'node:fs';
2
+ import { EOL } from 'node:os';
3
+ import { join } from 'node:path';
4
+ import { AST } from '@codemod-utils/ast-javascript';
5
+ function createDefaultExport(file) {
6
+ let properties;
7
+ AST.traverse(file, {
8
+ visitAssignmentExpression(path) {
9
+ if (path.node.left.type !== 'MemberExpression' ||
10
+ path.node.left.object.type !== 'Identifier' ||
11
+ path.node.left.object.name !== 'module' ||
12
+ path.node.left.property.type !== 'Identifier' ||
13
+ path.node.left.property.name !== 'exports') {
14
+ return false;
15
+ }
16
+ if (path.node.right.type !== 'ObjectExpression') {
17
+ return false;
18
+ }
19
+ properties = path.node.right.properties;
20
+ return false;
21
+ },
22
+ });
23
+ if (properties === undefined) {
24
+ return file;
25
+ }
26
+ const newFile = [`export default {};`, ``].join(EOL);
27
+ const ast = AST.traverse(newFile, {
28
+ visitExportDefaultDeclaration(path) {
29
+ path.node.declaration = AST.builders.objectExpression(properties);
30
+ return false;
31
+ },
32
+ });
33
+ return AST.print(ast);
34
+ }
35
+ export function convertToEsm(filePath, projectRoot) {
36
+ let file = readFileSync(join(projectRoot, filePath), 'utf8');
37
+ file = createDefaultExport(file);
38
+ writeFileSync(join(projectRoot, 'testem.mjs'), file, 'utf8');
39
+ rmSync(join(projectRoot, filePath));
40
+ }
@@ -0,0 +1,30 @@
1
+ import { writeFileSync } from 'node:fs';
2
+ import { EOL } from 'node:os';
3
+ import { join } from 'node:path';
4
+ export function createConfig(projectRoot) {
5
+ const defaultFile = [
6
+ `export default {`,
7
+ ` browser_args: {`,
8
+ ` Chrome: {`,
9
+ ` ci: [`,
10
+ ` // --no-sandbox is needed when running Chrome inside a container`,
11
+ ` process.env['CI'] ? '--no-sandbox' : null,`,
12
+ ` '--headless',`,
13
+ ` '--disable-dev-shm-usage',`,
14
+ ` '--disable-software-rasterizer',`,
15
+ ` '--mute-audio',`,
16
+ ` '--remote-debugging-port=0',`,
17
+ ` '--window-size=1440,900',`,
18
+ ` ].filter(Boolean),`,
19
+ ` },`,
20
+ ` },`,
21
+ ` browser_start_timeout: 120,`,
22
+ ` disable_watching: true,`,
23
+ ` launch_in_ci: ['Chrome'],`,
24
+ ` launch_in_dev: ['Chrome'],`,
25
+ ` test_page: 'tests/index.html?hidepassed&nolint',`,
26
+ `};`,
27
+ ``,
28
+ ].join(EOL);
29
+ writeFileSync(join(projectRoot, 'testem.mjs'), defaultFile, 'utf8');
30
+ }
@@ -0,0 +1,2 @@
1
+ export * from './convert-to-esm.js';
2
+ export * from './create-config.js';
@@ -0,0 +1,23 @@
1
+ import { findFiles } from '@codemod-utils/files';
2
+ import { convertToEsm, createConfig } from './update-config/index.js';
3
+ function findUserConfig(projectRoot) {
4
+ const filePaths = findFiles('{testem,.testem}.{cjs,js,json,mjs,yml}', {
5
+ projectRoot,
6
+ });
7
+ if (filePaths.length === 1) {
8
+ return filePaths[0];
9
+ }
10
+ return undefined;
11
+ }
12
+ export function updateConfig(options) {
13
+ const { projectRoot } = options;
14
+ const filePath = findUserConfig(projectRoot);
15
+ if (filePath === undefined) {
16
+ createConfig(projectRoot);
17
+ return;
18
+ }
19
+ if (filePath.endsWith('.cjs') || filePath.endsWith('.js')) {
20
+ convertToEsm(filePath, projectRoot);
21
+ return;
22
+ }
23
+ }
@@ -1,10 +1,11 @@
1
1
  import { convertToMap, convertToObject, } from '@codemod-utils/package-json';
2
2
  const latestVersions = {
3
- 'ember-testem': '^0.5.0',
3
+ 'ember-testem': '^0.5.1',
4
4
  };
5
5
  export function updateDependencies(packageJson, options) {
6
6
  const devDependencies = convertToMap(packageJson['devDependencies']);
7
7
  devDependencies.set('ember-testem', latestVersions['ember-testem']);
8
+ devDependencies.delete('testem');
8
9
  if (options.packageType === 'v2-addon') {
9
10
  // TODO
10
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "install-ember-testem",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "description": "Codemod to install ember-testem",
5
5
  "keywords": [
6
6
  "codemod",
@@ -10,7 +10,7 @@
10
10
  "repository": {
11
11
  "type": "git",
12
12
  "url": "https://github.com/ijlee2/ember-testem.git",
13
- "directory": "packages/ember-testem"
13
+ "directory": "packages/install-ember-testem"
14
14
  },
15
15
  "license": "MIT",
16
16
  "author": "Isaac J. Lee",