Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/encore.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import pc from 'picocolors';
import yargsParser from 'yargs-parser';

import parseRuntime from '../lib/config/parse-runtime.js';
import parseRuntime from '../lib/config/parse-runtime.ts';
import context from '../lib/context.js';
import featuresHelper from '../lib/features.js';
import logger from '../lib/logger.js';
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import yargsParser from 'yargs-parser';

import configGenerator from './lib/config-generator.js';
import parseRuntime from './lib/config/parse-runtime.js';
import validator from './lib/config/validator.js';
import parseRuntime from './lib/config/parse-runtime.ts';
import validator from './lib/config/validator.ts';
import context from './lib/context.js';
import EncoreProxy from './lib/EncoreProxy.js';
import WebpackConfig from './lib/WebpackConfig.js';
Expand Down
2 changes: 1 addition & 1 deletion lib/WebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import crypto from 'crypto';
import fs from 'fs';
import path from 'path';

import pathUtil from './config/path-util.js';
import pathUtil from './config/path-util.ts';
import featuresHelper from './features.js';
import logger from './logger.js';
import regexpEscaper from './utils/regexp-escaper.ts';
Expand Down
2 changes: 1 addition & 1 deletion lib/config-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { fileURLToPath } from 'url';

import tmp from 'tmp';

import pathUtil from './config/path-util.js';
import pathUtil from './config/path-util.ts';
import babelLoaderUtil from './loaders/babel.ts';
import cssExtractLoaderUtil from './loaders/css-extract.ts';
// loaders utils
Expand Down
21 changes: 21 additions & 0 deletions lib/config/RuntimeConfig.js → lib/config/RuntimeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,27 @@
*/

class RuntimeConfig {
command: string | number | null;
context: string | null;
isValidCommand: boolean;
environment: string;

useDevServer: boolean;
devServerServerType: string | null;
// see config-generator - getWebpackConfig()
devServerFinalIsHttps: boolean | null;
devServerHost: string | null;
devServerPort: string | number | null;
devServerPublic: string | null;
devServerKeepPublicPath: boolean;
outputJson: boolean;
profile: boolean;

babelRcFileExists: boolean | null;

helpRequested: boolean;
verbose: boolean;

constructor() {
this.command = null;
this.context = null;
Expand Down
16 changes: 8 additions & 8 deletions lib/config/parse-runtime.js → lib/config/parse-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@

import path from 'path';

import type { Arguments } from 'yargs-parser';

import packageUp from '../utils/package-up.ts';
// .js (not .ts): RuntimeConfig is exposed in this module's emitted .d.ts, and
// rewriteRelativeImportExtensions does NOT rewrite .ts -> .js inside .d.ts files
// (only in emitted .js). tsc still resolves .js -> the .ts source here.
Comment on lines +15 to +17

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When all files will be migrated to .ts, we should:

  1. modify all .ts imports to .js
  2. remove allowImportingTsExtensions and rewriteRelativeImportExtensions compiler options
  3. tweak ESLint configuration if necessary

import RuntimeConfig from './RuntimeConfig.js';

/**
* @param {object} argv
* @param {string} cwd
* @returns {RuntimeConfig}
*/
export default function (argv, cwd) {
export default function (argv: Arguments, cwd: string): RuntimeConfig {
const runtimeConfig = new RuntimeConfig();
runtimeConfig.command = argv._[0];
runtimeConfig.command = argv._[0] ?? null;

switch (runtimeConfig.command) {
case 'dev':
Expand Down Expand Up @@ -59,7 +59,7 @@ export default function (argv, cwd) {
if (typeof runtimeConfig.context === 'undefined') {
const packagesPath = packageUp({ cwd });

if (null === packagesPath) {
if (undefined === packagesPath) {
throw new Error(
'Cannot determine webpack context. (Are you executing webpack from a directory outside of your project?). Try passing the --context option.'
);
Expand Down
34 changes: 9 additions & 25 deletions lib/config/path-util.js → lib/config/path-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,20 @@
* file that was distributed with this source code.
*/

/**
* @import WebpackConfig from '../WebpackConfig.js'
*/

/**
* @import RuntimeConfig from './RuntimeConfig.js'
*/

import path from 'path';

import logger from '../logger.js';
import type WebpackConfig from '../WebpackConfig.js';
// .js (not .ts): RuntimeConfig is exposed in this module's emitted .d.ts, and
// rewriteRelativeImportExtensions does NOT rewrite .ts -> .js inside .d.ts files
// (only in emitted .js). tsc still resolves .js -> the .ts source here.
import type RuntimeConfig from './RuntimeConfig.js';

export default {
/**
* Determines the "contentBase" to use for the devServer.
*
* @param {WebpackConfig} webpackConfig
* @returns {string}
*/
getContentBase(webpackConfig) {
getContentBase(webpackConfig: WebpackConfig): string {
// strip trailing slash (for Unix or Windows)
const outputPath = webpackConfig.outputPath.replace(/\/$/, '').replace(/\\$/, '');
// use the manifestKeyPrefix if available
Expand Down Expand Up @@ -66,11 +60,8 @@ export default {

/**
* Returns the output path, but as a relative string (e.g. web/build)
*
* @param {WebpackConfig} webpackConfig
* @returns {string}
*/
getRelativeOutputPath(webpackConfig) {
getRelativeOutputPath(webpackConfig: WebpackConfig): string {
return webpackConfig.outputPath.replace(webpackConfig.getContext() + path.sep, '');
},

Expand All @@ -79,11 +70,8 @@ export default {
*
* Most importantly, this runs some sanity checks to make sure that it's
* ok to use the publicPath as the manifestKeyPrefix.
*
* @param {WebpackConfig} webpackConfig
* @returns {void}
*/
validatePublicPathAndManifestKeyPrefix(webpackConfig) {
validatePublicPathAndManifestKeyPrefix(webpackConfig: WebpackConfig): void {
if (webpackConfig.manifestKeyPrefix !== null) {
// nothing to check - they have manually set the key prefix
return;
Expand Down Expand Up @@ -131,11 +119,7 @@ export default {
}
},

/**
* @param {RuntimeConfig} runtimeConfig
* @returns {string}
*/
calculateDevServerUrl(runtimeConfig) {
calculateDevServerUrl(runtimeConfig: RuntimeConfig): string {
if (runtimeConfig.devServerFinalIsHttps === null) {
logger.warning(
'The final devServerFinalHttpsConfig was never calculated. This may cause some paths to incorrectly use or not use https and could be a bug.'
Expand Down
26 changes: 11 additions & 15 deletions lib/config/validator.js → lib/config/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,18 @@
* file that was distributed with this source code.
*/

/**
* @import WebpackConfig from '../WebpackConfig.js'
*/

import type WebpackConfig from '../WebpackConfig.js';
import logger from './../logger.js';
import pathUtil from './path-util.js';
import pathUtil from './path-util.ts';

class Validator {
/**
* @param {WebpackConfig} webpackConfig
*/
constructor(webpackConfig) {
webpackConfig: WebpackConfig;

constructor(webpackConfig: WebpackConfig) {
this.webpackConfig = webpackConfig;
}

validate() {
validate(): void {
this._validateBasic();

this._validatePublicPathAndManifestKeyPrefix();
Expand All @@ -32,7 +28,7 @@ class Validator {
this._validateCacheGroupNames();
}

_validateBasic() {
_validateBasic(): void {
if (this.webpackConfig.outputPath === null) {
throw new Error(
'Missing output path: Call setOutputPath() to control where the files will be written.'
Expand All @@ -57,11 +53,11 @@ class Validator {
}
}

_validatePublicPathAndManifestKeyPrefix() {
_validatePublicPathAndManifestKeyPrefix(): void {
pathUtil.validatePublicPathAndManifestKeyPrefix(this.webpackConfig);
}

_validateDevServer() {
_validateDevServer(): void {
if (!this.webpackConfig.useDevServer()) {
return;
}
Expand All @@ -86,7 +82,7 @@ class Validator {
}
}

_validateCacheGroupNames() {
_validateCacheGroupNames(): void {
for (const groupName of Object.keys(this.webpackConfig.cacheGroups)) {
if (['defaultVendors', 'default'].includes(groupName)) {
logger.warning(
Expand All @@ -97,7 +93,7 @@ class Validator {
}
}

export default function (webpackConfig) {
export default function (webpackConfig: WebpackConfig): void {
const validator = new Validator(webpackConfig);

validator.validate();
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/asset-output-display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import type FriendlyErrorsWebpackPlugin from '@kocal/friendly-errors-webpack-plugin';
import type { WebpackPluginInstance } from 'webpack';

import pathUtil from '../config/path-util.js';
import pathUtil from '../config/path-util.ts';
import AssetOutputDisplayPlugin from '../friendly-errors/asset-output-display-plugin.ts';
import type WebpackConfig from '../WebpackConfig.js';
import PluginPriorities from './plugin-priorities.ts';
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"@tsconfig/node22": "^22.0.5",
"@types/node": "^22.18.0",
"@types/semver": "^7.7.1",
"@types/yargs-parser": "21.0.3",
"@vue/babel-plugin-jsx": "^3.0.0",
"@vue/compiler-sfc": "^3.2.14",
"autoprefixer": "^10.2.0",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/WebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import path from 'path';
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import webpack from 'webpack';

import RuntimeConfig from '../lib/config/RuntimeConfig.js';
import RuntimeConfig from '../lib/config/RuntimeConfig.ts';
import logger from '../lib/logger.js';
import WebpackConfig from '../lib/WebpackConfig.js';

Expand Down
2 changes: 1 addition & 1 deletion test/config-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import webpack from 'webpack';
import { WebpackManifestPlugin } from 'webpack-manifest-plugin';

import configGenerator from '../lib/config-generator.js';
import RuntimeConfig from '../lib/config/RuntimeConfig.js';
import RuntimeConfig from '../lib/config/RuntimeConfig.ts';
import logger from '../lib/logger.js';
import WebpackConfig from '../lib/WebpackConfig.js';

Expand Down
2 changes: 1 addition & 1 deletion test/config/parse-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import fs from 'fs-extra';
import { describe, it, expect } from 'vitest';
import yargsParser from 'yargs-parser';

import parseArgv from '../../lib/config/parse-runtime.js';
import parseArgv from '../../lib/config/parse-runtime.ts';
import WebpackConfig from '../../lib/WebpackConfig.js';
import * as testSetup from '../helpers/setup.js';

Expand Down
4 changes: 2 additions & 2 deletions test/config/path-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import process from 'process';
import { describe, it, expect } from 'vitest';

import configGenerator from '../../lib/config-generator.js';
import pathUtil from '../../lib/config/path-util.js';
import RuntimeConfig from '../../lib/config/RuntimeConfig.js';
import pathUtil from '../../lib/config/path-util.ts';
import RuntimeConfig from '../../lib/config/RuntimeConfig.ts';
import WebpackConfig from '../../lib/WebpackConfig.js';

function createConfig() {
Expand Down
4 changes: 2 additions & 2 deletions test/config/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

import { describe, it, expect } from 'vitest';

import RuntimeConfig from '../../lib/config/RuntimeConfig.js';
import validator from '../../lib/config/validator.js';
import RuntimeConfig from '../../lib/config/RuntimeConfig.ts';
import validator from '../../lib/config/validator.ts';
import logger from '../../lib/logger.js';
import WebpackConfig from '../../lib/WebpackConfig.js';

Expand Down
2 changes: 1 addition & 1 deletion test/friendly-errors/transformers/missing-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import { describe, it, expect } from 'vitest';

import RuntimeConfig from '../../../lib/config/RuntimeConfig.js';
import RuntimeConfig from '../../../lib/config/RuntimeConfig.ts';
import transformFactory from '../../../lib/friendly-errors/transformers/missing-loader.ts';
import WebpackConfig from '../../../lib/WebpackConfig.js';

Expand Down
4 changes: 2 additions & 2 deletions test/helpers/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import httpServer from 'http-server';
import webpack from 'webpack';

import configGenerator from '../../lib/config-generator.js';
import parseRuntime from '../../lib/config/parse-runtime.js';
import validator from '../../lib/config/validator.js';
import parseRuntime from '../../lib/config/parse-runtime.ts';
import validator from '../../lib/config/validator.ts';
import WebpackConfig from '../../lib/WebpackConfig.js';
import { Assert } from './assert.js';

Expand Down
2 changes: 1 addition & 1 deletion test/loaders/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { fileURLToPath } from 'url';

import { describe, it, expect } from 'vitest';

import RuntimeConfig from '../../lib/config/RuntimeConfig.js';
import RuntimeConfig from '../../lib/config/RuntimeConfig.ts';
import babelLoader from '../../lib/loaders/babel.ts';
import WebpackConfig from '../../lib/WebpackConfig.js';

Expand Down
2 changes: 1 addition & 1 deletion test/loaders/css-extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import { describe, it, expect } from 'vitest';

import RuntimeConfig from '../../lib/config/RuntimeConfig.js';
import RuntimeConfig from '../../lib/config/RuntimeConfig.ts';
import cssExtractLoader from '../../lib/loaders/css-extract.ts';
import WebpackConfig from '../../lib/WebpackConfig.js';

Expand Down
2 changes: 1 addition & 1 deletion test/loaders/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import { describe, it, expect } from 'vitest';

import RuntimeConfig from '../../lib/config/RuntimeConfig.js';
import RuntimeConfig from '../../lib/config/RuntimeConfig.ts';
import cssLoader from '../../lib/loaders/css.ts';
import WebpackConfig from '../../lib/WebpackConfig.js';

Expand Down
2 changes: 1 addition & 1 deletion test/loaders/handlebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import { describe, it, expect } from 'vitest';

import RuntimeConfig from '../../lib/config/RuntimeConfig.js';
import RuntimeConfig from '../../lib/config/RuntimeConfig.ts';
import handlebarsLoader from '../../lib/loaders/handlebars.ts';
import WebpackConfig from '../../lib/WebpackConfig.js';

Expand Down
Loading