Skip to content
This repository has been archived by the owner on Apr 14, 2022. It is now read-only.

Commit

Permalink
chore: dependency updates and code cleanup (#684)
Browse files Browse the repository at this point in the history
  • Loading branch information
muenzpraeger authored Sep 16, 2020
1 parent 6880933 commit 134a212
Show file tree
Hide file tree
Showing 16 changed files with 539 additions and 504 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
## Changelog

### 2020-09-16

**create-lwc-app 2.1.7**

- Code cleanup and dependency updates

**lwc-services 2.1.7**

- Code cleanup and dependency updates

### 2020-08-31

**lwc-services 2.1.6**
Expand Down
2 changes: 1 addition & 1 deletion packages/create-lwc-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-lwc-app",
"version": "2.1.6",
"version": "2.1.7",
"author": "René Winkelmeyer @muenzpraeger",
"bin": {
"create-lwc-app": "./bin/run"
Expand Down
18 changes: 9 additions & 9 deletions packages/create-lwc-app/src/generators/createGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { execSync } from 'child_process'
import * as fs from 'fs'
import * as path from 'path'
import { existsSync, mkdirSync, readFileSync } from 'fs'
import { join, resolve } from 'path'
import * as Generator from 'yeoman-generator'

import { messages } from '../messages/createGenerator'
Expand All @@ -26,7 +26,7 @@ try {
}

const pkgJson = JSON.parse(
fs.readFileSync(__dirname + '/../../package.json', 'utf8')
readFileSync(__dirname + '/../../package.json', 'utf8')
)
const LWC_SERVICES_VERSION = pkgJson.version
const filesDefault = [
Expand Down Expand Up @@ -408,16 +408,16 @@ class CreateGenerator extends Generator {
this.pjson.bugs =
this.defaults.bugs ||
`https://github.com/${this.pjson.repository}/issues`
const targetPath: string = path.resolve(this.pjson.name)
if (!fs.existsSync(targetPath)) {
fs.mkdirSync(targetPath, { recursive: true })
const targetPath: string = resolve(this.pjson.name)
if (!existsSync(targetPath)) {
mkdirSync(targetPath, { recursive: true })
}
this.destinationRoot(targetPath)
process.chdir(this.destinationRoot())
}

writing() {
this.sourceRoot(path.join(__dirname, '../../templates'))
this.sourceRoot(join(__dirname, '../../templates'))

this.fs.writeJSON(
this.destinationPath('./package.json'),
Expand Down Expand Up @@ -545,7 +545,7 @@ class CreateGenerator extends Generator {
)
})
const fileExtension = this.typescript ? '.ts' : '.js'
if (!fs.existsSync('src')) {
if (!existsSync('src')) {
this.fs.copyTpl(
this.templatePath('src/client/index.non-wc.html'),
this.destinationPath(
Expand Down Expand Up @@ -713,7 +713,7 @@ class CreateGenerator extends Generator {
}

if (this.clientserver) {
if (!fs.existsSync('src')) {
if (!existsSync('src')) {
this.fs.copyTpl(
this.templatePath('src/server/api'.concat(fileExtension)),
this.destinationPath(
Expand Down
4 changes: 2 additions & 2 deletions packages/create-lwc-app/templates/src/server/server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const compression = require('compression');
const helmet = require('helmet');
const express = require('express');
import * as path from 'path';
import { resolve } from 'path';

const app = express();
app.use(helmet());
Expand All @@ -14,7 +14,7 @@ const DIST_DIR = './dist';
app.use(express.static(DIST_DIR));

app.use('*', (req: any, res: any) => {
res.sendFile(path.resolve(DIST_DIR, 'index.html'));
res.sendFile(resolve(DIST_DIR, 'index.html'));
});

app.listen(PORT, () =>
Expand Down
8 changes: 5 additions & 3 deletions packages/lwc-services/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lwc-services",
"version": "2.1.6",
"version": "2.1.7",
"author": "René Winkelmeyer @muenzpraeger",
"bin": {
"lwc-services": "./bin/run"
Expand Down Expand Up @@ -33,15 +33,17 @@
"cross-env": "^7.0.2",
"deepmerge": "^4.0.0",
"error-overlay-webpack-plugin": "^0.4.1",
"eslint": "^7.3",
"eslint": "^7.2.0",
"eslint-plugin-inclusive-language": "^1.2.0",
"globby": "^11.0.0",
"html-webpack-plugin": "^4.0.1",
"husky": "^4.2.3",
"jest": "^26",
"lint-staged": "^10.0.9",
"lwc": "^1.7.0",
"node-emoji": "^1.10.0",
"nodemon": "^2.0.1",
"prettier": "^2.0",
"prettier": "^2.0.2",
"rimraf": "^3.0",
"rollup": "^2.3.4",
"rollup-plugin-compat": "^0.22.0",
Expand Down
16 changes: 8 additions & 8 deletions packages/lwc-services/src/commands/build.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Command, flags } from '@oclif/command'
import * as fs from 'fs'
import * as path from 'path'
import { existsSync } from 'fs'
import { resolve } from 'path'
import * as rimraf from 'rimraf'

import { lwcConfig } from '../config/lwcConfig'
Expand All @@ -11,7 +11,7 @@ import { analyzeStats } from '../utils/webpack/statsAnalyzer'
import { migrateModuleResolution } from '../utils/migration'
const spawn = require('child_process').spawn

const rollupConfig = path.resolve(__dirname, '../config/rollup.config.js')
const rollupConfig = resolve(__dirname, '../config/rollup.config.js')

function buildWebpack(webpackConfig: any) {
const webpack = require('webpack')
Expand Down Expand Up @@ -89,14 +89,14 @@ export default class Build extends Command {
const BUILD_DIR = lwcConfig.buildDir

// Check if given source directory exists. If not we're exiting.
if (!fs.existsSync(SOURCE_DIR)) {
if (!existsSync(SOURCE_DIR)) {
log(messages.errors.no_source_dir, SOURCE_DIR)
return
}

// Clearing build directory, if the user didn't override.
if (!flags.noclear) {
if (fs.existsSync(BUILD_DIR)) {
if (existsSync(BUILD_DIR)) {
rimraf.sync(BUILD_DIR)
log(messages.logs.clear)
}
Expand All @@ -107,7 +107,7 @@ export default class Build extends Command {
if (flags.bundler === 'webpack') {
// Check if custom webpack config is passed, and if it really exists.
if (flags.webpack) {
if (!fs.existsSync(flags.webpack)) {
if (!existsSync(flags.webpack)) {
log(messages.errors.no_webpack)
return
}
Expand All @@ -119,7 +119,7 @@ export default class Build extends Command {

if (flags.webpack) {
log(messages.logs.custom_configuration)
webpackConfigCustom = require(path.resolve(
webpackConfigCustom = require(resolve(
process.cwd(),
flags.webpack
))
Expand All @@ -136,7 +136,7 @@ export default class Build extends Command {
}

if (flags.destination && flags.destination !== lwcConfig.buildDir) {
webpackConfig.output.path = path.resolve(
webpackConfig.output.path = resolve(
process.cwd(),
flags.destination
)
Expand Down
29 changes: 13 additions & 16 deletions packages/lwc-services/src/commands/sniff.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Command, flags } from '@oclif/command'
import * as fs from 'fs'
import * as path from 'path'
import { copyFileSync, existsSync, mkdirSync, writeFileSync } from 'fs'
import { join, resolve } from 'path'
import util = require('util')
import * as webpackMerge from 'webpack-merge'

Expand All @@ -10,7 +10,7 @@ import { generateWebpackConfig } from '../config/webpack.config'
import { messages } from '../messages/sniff'
import { log, welcome } from '../utils/logger'

const rollupConfig = path.resolve(__dirname, '../config/rollup.config.js')
const rollupConfig = resolve(__dirname, '../config/rollup.config.js')

export default class Sniff extends Command {
static description = messages.description
Expand Down Expand Up @@ -43,8 +43,8 @@ export default class Sniff extends Command {
return
}

if (!fs.existsSync(flags.directory)) {
fs.mkdirSync(flags.directory)
if (!existsSync(flags.directory)) {
mkdirSync(flags.directory)
}

log(messages.logs.calculating_configurations)
Expand All @@ -53,7 +53,7 @@ export default class Sniff extends Command {
if (flags.webpack) {
// Merging custom webpack config file
log(messages.logs.custom_configuration)
const webpackConfigCustom = require(path.resolve(
const webpackConfigCustom = require(resolve(
process.cwd(),
flags.webpack
))
Expand All @@ -67,23 +67,20 @@ export default class Sniff extends Command {

const inspectOptions = { depth: null }

fs.writeFileSync(
path.join(flags.directory, 'jest.config.js'),
writeFileSync(
join(flags.directory, 'jest.config.js'),
'module.exports = ' + util.inspect(jestConfig, inspectOptions)
)
log(messages.logs.write_webpack_config)
fs.writeFileSync(
path.join(flags.directory, 'webpack.config.js'),
writeFileSync(
join(flags.directory, 'webpack.config.js'),
'module.exports = ' + util.inspect(webpackConfig, inspectOptions)
)
log(messages.logs.write_rollup_config)
fs.copyFileSync(
rollupConfig,
path.join(flags.directory, 'rollup.config.js')
)
copyFileSync(rollupConfig, join(flags.directory, 'rollup.config.js'))
log(messages.logs.write_lwc_config)
fs.writeFileSync(
path.join(flags.directory, 'lwc-services.config.js'),
writeFileSync(
join(flags.directory, 'lwc-services.config.js'),
'module.exports = ' + util.inspect(defaultLwcConfig, inspectOptions)
)
log(messages.logs.enjoy)
Expand Down
17 changes: 7 additions & 10 deletions packages/lwc-services/src/commands/test/unit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Command, flags } from '@oclif/command'
import merge = require('deepmerge')
import * as fs from 'fs'
import * as path from 'path'
import { existsSync } from 'fs'
import { resolve } from 'path'

import { jestConfig } from '../../config/jestConfig'
import { messages } from '../../messages/test_unit'
Expand Down Expand Up @@ -43,23 +43,20 @@ export default class Test extends Command {
// Inspiration of this implementation taken from https://github.com/salesforce/lwc-jest. Thank you, Trevor!
let jestFinalConfig = jestConfig

if (
!fs.existsSync('jest.config.js') &&
!fs.existsSync('jest.config.json')
) {
if (!existsSync('jest.config.js') && !existsSync('jest.config.json')) {
log(messages.logs.default_configuration)
} else {
log(messages.logs.custom_configuration)
// Yay, someone uses a custom configuration.
if (fs.existsSync('jest.config.js')) {
const jestCustomConfigJs = require(path.resolve(
if (existsSync('jest.config.js')) {
const jestCustomConfigJs = require(resolve(
process.cwd(),
'jest.config.js'
))
jestFinalConfig = merge(jestFinalConfig, jestCustomConfigJs)
}
if (fs.existsSync('jest.config.json')) {
const jestCustomConfigJson = require(path.resolve(
if (existsSync('jest.config.json')) {
const jestCustomConfigJson = require(resolve(
process.cwd(),
'jest.config.json'
))
Expand Down
10 changes: 5 additions & 5 deletions packages/lwc-services/src/commands/watch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Command, flags } from '@oclif/command'
import cli from 'cli-ux'
import * as fs from 'fs'
import * as path from 'path'
import { existsSync } from 'fs'
import { resolve } from 'path'
import * as webpack from 'webpack'
import * as webpackMerge from 'webpack-merge'

Expand All @@ -11,7 +11,7 @@ import { messages } from '../messages/watch'
import { log, welcome } from '../utils/logger'
const spawn = require('child_process').spawn

const rollupConfig = path.resolve(__dirname, '../config/rollup.config.js')
const rollupConfig = resolve(__dirname, '../config/rollup.config.js')

export default class Watch extends Command {
static description = messages.description
Expand Down Expand Up @@ -62,7 +62,7 @@ export default class Watch extends Command {
if (flags.bundler === 'webpack') {
// Check if custom webpack config is passed, and if it really exists.
if (flags.webpack) {
if (!fs.existsSync(flags.webpack)) {
if (!existsSync(flags.webpack)) {
log(messages.errors.no_webpack)
return
}
Expand All @@ -75,7 +75,7 @@ export default class Watch extends Command {
// Merging custom webpack config file
if (flags.webpack) {
log(messages.logs.custom_configuration)
const webpackConfigCustom = require(path.resolve(
const webpackConfigCustom = require(resolve(
process.cwd(),
flags.webpack
))
Expand Down
21 changes: 6 additions & 15 deletions packages/lwc-services/src/config/jestConfig.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
const jestLwcConfig = require('@lwc/jest-preset')
import merge = require('deepmerge')
import * as path from 'path'
// const jestLwcConfig = require('@lwc/jest-preset')
// import merge = require('deepmerge')
import { resolve } from 'path'

const jestDefaultConfig = {
rootDir: process.cwd(),
transformIgnorePatterns: [
'/node_modules/(?:(?!lightning-mocks.*(js|html|css)))*$'
],
resolver: path.resolve(__dirname, '../utils/resolver.js'),
testPathIgnorePatterns: [
'<rootDir>/node_modules/',
'<rootDir>/test/specs/'
],
collectCoverageFrom: ['src/**/*.js'],
snapshotSerializers: [require.resolve('@lwc/jest-serializer')]
preset: '@lwc/jest-preset',
resolver: resolve(__dirname, '../utils/resolver.js')
}

export const jestConfig = merge(jestLwcConfig, jestDefaultConfig)
export const jestConfig = jestDefaultConfig
4 changes: 2 additions & 2 deletions packages/lwc-services/src/config/lwcConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import merge = require('deepmerge')
import * as path from 'path'
import { resolve } from 'path'

interface ResourceFolder {
from: string
Expand Down Expand Up @@ -100,7 +100,7 @@ export const defaultLwcConfig: Config = {
function buildConfig(): Config {
let combinedConfig: Config = defaultLwcConfig
try {
const fileName = path.resolve(process.cwd(), 'lwc-services.config.js')
const fileName = resolve(process.cwd(), 'lwc-services.config.js')
const config = require(fileName)
combinedConfig = merge(defaultLwcConfig, config)
return combinedConfig
Expand Down
Loading

0 comments on commit 134a212

Please sign in to comment.