next-translate-plugin 2.0.0 โ 2.0.2
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/lib/cjs/index.js +7 -7
- package/lib/cjs/templateAppDir.js +2 -1
- package/lib/cjs/utils.js +5 -1
- package/lib/esm/index.js +7 -7
- package/lib/esm/templateAppDir.js +3 -2
- package/lib/esm/utils.js +3 -0
- package/package.json +5 -3
- package/postinstall-message.js +18 -0
- package/templateAppDir/package.json +7 -0
- package/utils.d.ts +1 -0
package/lib/cjs/index.js
CHANGED
|
@@ -48,9 +48,9 @@ var possiblePageDirs = __spreadArray([
|
|
|
48
48
|
function nextTranslate(nextConfig) {
|
|
49
49
|
if (nextConfig === void 0) { nextConfig = {}; }
|
|
50
50
|
var basePath = pkgDir();
|
|
51
|
-
var
|
|
51
|
+
var dir = path_1.default.resolve(path_1.default.relative(basePath, process.env.NEXT_TRANSLATE_PATH || '.'));
|
|
52
52
|
var nextConfigI18n = nextConfig.i18n || {};
|
|
53
|
-
var _a = require(path_1.default.join(
|
|
53
|
+
var _a = require(path_1.default.join(dir, 'i18n')), _b = _a.locales, locales = _b === void 0 ? nextConfigI18n.locales || [] : _b, _c = _a.defaultLocale, defaultLocale = _c === void 0 ? nextConfigI18n.defaultLocale || 'en' : _c, _d = _a.domains, domains = _d === void 0 ? nextConfigI18n.domains : _d, _e = _a.localeDetection, localeDetection = _e === void 0 ? nextConfigI18n.localeDetection : _e, _f = _a.loader, loader = _f === void 0 ? true : _f, pagesInDir = _a.pagesInDir, restI18n = __rest(_a, ["locales", "defaultLocale", "domains", "localeDetection", "loader", "pagesInDir"]);
|
|
54
54
|
var nextConfigWithI18n = __assign(__assign({}, nextConfig), { i18n: {
|
|
55
55
|
locales: locales,
|
|
56
56
|
defaultLocale: defaultLocale,
|
|
@@ -62,20 +62,20 @@ function nextTranslate(nextConfig) {
|
|
|
62
62
|
if (!pagesInDir) {
|
|
63
63
|
for (var _i = 0, possiblePageDirs_1 = possiblePageDirs; _i < possiblePageDirs_1.length; _i++) {
|
|
64
64
|
var possiblePageDir = possiblePageDirs_1[_i];
|
|
65
|
-
if (fs_1.default.existsSync(path_1.default.join(
|
|
65
|
+
if (fs_1.default.existsSync(path_1.default.join(dir, possiblePageDir))) {
|
|
66
66
|
pagesInDir = possiblePageDir;
|
|
67
67
|
isAppDirNext13 = appDirNext13.includes(possiblePageDir);
|
|
68
68
|
break;
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
if (!pagesInDir || !fs_1.default.existsSync(path_1.default.join(
|
|
72
|
+
if (!pagesInDir || !fs_1.default.existsSync(path_1.default.join(dir, pagesInDir))) {
|
|
73
73
|
return nextConfigWithI18n;
|
|
74
74
|
}
|
|
75
|
-
var pagesPath = path_1.default.join(
|
|
75
|
+
var pagesPath = path_1.default.join(dir, pagesInDir);
|
|
76
76
|
var app = fs_1.default.readdirSync(pagesPath).find(function (page) { return page.startsWith('_app.'); });
|
|
77
77
|
if (app) {
|
|
78
|
-
var appPkg = (0, utils_1.parseFile)(
|
|
78
|
+
var appPkg = (0, utils_1.parseFile)(dir, path_1.default.join(pagesPath, app));
|
|
79
79
|
var defaultExport = (0, utils_1.getDefaultExport)(appPkg);
|
|
80
80
|
if (defaultExport) {
|
|
81
81
|
var isGetInitialProps = (0, utils_1.hasStaticName)(appPkg, defaultExport, 'getInitialProps');
|
|
@@ -92,7 +92,7 @@ function nextTranslate(nextConfig) {
|
|
|
92
92
|
config.module = {};
|
|
93
93
|
if (!config.module.rules)
|
|
94
94
|
config.module.rules = [];
|
|
95
|
-
config.resolve.alias = __assign(__assign({}, (config.resolve.alias || {})), { '@next-translate-root': path_1.default.resolve(
|
|
95
|
+
config.resolve.alias = __assign(__assign({}, (config.resolve.alias || {})), { '@next-translate-root': path_1.default.resolve(dir) });
|
|
96
96
|
if (!loader)
|
|
97
97
|
return config;
|
|
98
98
|
config.module.rules.push({
|
|
@@ -6,7 +6,8 @@ var defaultDynamicExport = "export const dynamic = 'force-dynamic';";
|
|
|
6
6
|
function templateAppDir(pagePkg, _a) {
|
|
7
7
|
var _b = _a === void 0 ? {} : _a, _c = _b.hasLoadLocaleFrom, hasLoadLocaleFrom = _c === void 0 ? false : _c, _d = _b.pageNoExt, pageNoExt = _d === void 0 ? '/' : _d, _e = _b.normalizedResourcePath, normalizedResourcePath = _e === void 0 ? '' : _e, _f = _b.normalizedPagesPath, normalizedPagesPath = _f === void 0 ? '' : _f;
|
|
8
8
|
var code = pagePkg.getCode();
|
|
9
|
-
var
|
|
9
|
+
var codeWithoutComments = (0, utils_1.removeCommentsFromCode)(code).trim();
|
|
10
|
+
var isClientCode = clientLine.some(function (line) { return codeWithoutComments.startsWith(line); });
|
|
10
11
|
var isPage = pageNoExt.endsWith('/page') && normalizedResourcePath.startsWith(normalizedPagesPath);
|
|
11
12
|
if (!isPage && !isClientCode)
|
|
12
13
|
return code;
|
package/lib/cjs/utils.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
23
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.interceptExport = exports.isNotExportModifier = exports.hasHOC = exports.isPageToIgnore = exports.hasStaticName = exports.getStaticName = exports.hasExportName = exports.getDefaultExport = exports.getNamedExport = exports.resolveIdentifier = exports.resolveParenthesis = exports.getImportedNames = exports.getSymbol = exports.parseCode = exports.parseFile = exports.getFilePkg = exports.getTsCompilerOptions = exports.overwriteLoadLocales = exports.getDefaultAppJs = exports.defaultLoader = void 0;
|
|
26
|
+
exports.removeCommentsFromCode = exports.interceptExport = exports.isNotExportModifier = exports.hasHOC = exports.isPageToIgnore = exports.hasStaticName = exports.getStaticName = exports.hasExportName = exports.getDefaultExport = exports.getNamedExport = exports.resolveIdentifier = exports.resolveParenthesis = exports.getImportedNames = exports.getSymbol = exports.parseCode = exports.parseFile = exports.getFilePkg = exports.getTsCompilerOptions = exports.overwriteLoadLocales = exports.getDefaultAppJs = exports.defaultLoader = void 0;
|
|
27
27
|
var typescript_1 = __importDefault(require("typescript"));
|
|
28
28
|
var specFileOrFolderRgx = /(__mocks__|__tests__)|(\.(spec|test)\.(tsx|ts|js|jsx)$)/;
|
|
29
29
|
exports.defaultLoader = '(l, n) => import(`@next-translate-root/locales/${l}/${n}`).then(m => m.default)';
|
|
@@ -350,3 +350,7 @@ function interceptExport(filePkg, exportName, defaultLocalName) {
|
|
|
350
350
|
return finalLocalName;
|
|
351
351
|
}
|
|
352
352
|
exports.interceptExport = interceptExport;
|
|
353
|
+
function removeCommentsFromCode(code) {
|
|
354
|
+
return code.replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm, '');
|
|
355
|
+
}
|
|
356
|
+
exports.removeCommentsFromCode = removeCommentsFromCode;
|
package/lib/esm/index.js
CHANGED
|
@@ -43,9 +43,9 @@ var possiblePageDirs = __spreadArray([
|
|
|
43
43
|
function nextTranslate(nextConfig) {
|
|
44
44
|
if (nextConfig === void 0) { nextConfig = {}; }
|
|
45
45
|
var basePath = pkgDir();
|
|
46
|
-
var
|
|
46
|
+
var dir = path.resolve(path.relative(basePath, process.env.NEXT_TRANSLATE_PATH || '.'));
|
|
47
47
|
var nextConfigI18n = nextConfig.i18n || {};
|
|
48
|
-
var _a = require(path.join(
|
|
48
|
+
var _a = require(path.join(dir, 'i18n')), _b = _a.locales, locales = _b === void 0 ? nextConfigI18n.locales || [] : _b, _c = _a.defaultLocale, defaultLocale = _c === void 0 ? nextConfigI18n.defaultLocale || 'en' : _c, _d = _a.domains, domains = _d === void 0 ? nextConfigI18n.domains : _d, _e = _a.localeDetection, localeDetection = _e === void 0 ? nextConfigI18n.localeDetection : _e, _f = _a.loader, loader = _f === void 0 ? true : _f, pagesInDir = _a.pagesInDir, restI18n = __rest(_a, ["locales", "defaultLocale", "domains", "localeDetection", "loader", "pagesInDir"]);
|
|
49
49
|
var nextConfigWithI18n = __assign(__assign({}, nextConfig), { i18n: {
|
|
50
50
|
locales: locales,
|
|
51
51
|
defaultLocale: defaultLocale,
|
|
@@ -57,20 +57,20 @@ function nextTranslate(nextConfig) {
|
|
|
57
57
|
if (!pagesInDir) {
|
|
58
58
|
for (var _i = 0, possiblePageDirs_1 = possiblePageDirs; _i < possiblePageDirs_1.length; _i++) {
|
|
59
59
|
var possiblePageDir = possiblePageDirs_1[_i];
|
|
60
|
-
if (fs.existsSync(path.join(
|
|
60
|
+
if (fs.existsSync(path.join(dir, possiblePageDir))) {
|
|
61
61
|
pagesInDir = possiblePageDir;
|
|
62
62
|
isAppDirNext13 = appDirNext13.includes(possiblePageDir);
|
|
63
63
|
break;
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
-
if (!pagesInDir || !fs.existsSync(path.join(
|
|
67
|
+
if (!pagesInDir || !fs.existsSync(path.join(dir, pagesInDir))) {
|
|
68
68
|
return nextConfigWithI18n;
|
|
69
69
|
}
|
|
70
|
-
var pagesPath = path.join(
|
|
70
|
+
var pagesPath = path.join(dir, pagesInDir);
|
|
71
71
|
var app = fs.readdirSync(pagesPath).find(function (page) { return page.startsWith('_app.'); });
|
|
72
72
|
if (app) {
|
|
73
|
-
var appPkg = parseFile(
|
|
73
|
+
var appPkg = parseFile(dir, path.join(pagesPath, app));
|
|
74
74
|
var defaultExport = getDefaultExport(appPkg);
|
|
75
75
|
if (defaultExport) {
|
|
76
76
|
var isGetInitialProps = hasStaticName(appPkg, defaultExport, 'getInitialProps');
|
|
@@ -87,7 +87,7 @@ function nextTranslate(nextConfig) {
|
|
|
87
87
|
config.module = {};
|
|
88
88
|
if (!config.module.rules)
|
|
89
89
|
config.module.rules = [];
|
|
90
|
-
config.resolve.alias = __assign(__assign({}, (config.resolve.alias || {})), { '@next-translate-root': path.resolve(
|
|
90
|
+
config.resolve.alias = __assign(__assign({}, (config.resolve.alias || {})), { '@next-translate-root': path.resolve(dir) });
|
|
91
91
|
if (!loader)
|
|
92
92
|
return config;
|
|
93
93
|
config.module.rules.push({
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { interceptExport, overwriteLoadLocales, getNamedExport } from "./utils";
|
|
1
|
+
import { interceptExport, overwriteLoadLocales, getNamedExport, removeCommentsFromCode } from "./utils";
|
|
2
2
|
var clientLine = ['"use client"', "'use client'"];
|
|
3
3
|
var defaultDynamicExport = "export const dynamic = 'force-dynamic';";
|
|
4
4
|
export default function templateAppDir(pagePkg, _a) {
|
|
5
5
|
var _b = _a === void 0 ? {} : _a, _c = _b.hasLoadLocaleFrom, hasLoadLocaleFrom = _c === void 0 ? false : _c, _d = _b.pageNoExt, pageNoExt = _d === void 0 ? '/' : _d, _e = _b.normalizedResourcePath, normalizedResourcePath = _e === void 0 ? '' : _e, _f = _b.normalizedPagesPath, normalizedPagesPath = _f === void 0 ? '' : _f;
|
|
6
6
|
var code = pagePkg.getCode();
|
|
7
|
-
var
|
|
7
|
+
var codeWithoutComments = removeCommentsFromCode(code).trim();
|
|
8
|
+
var isClientCode = clientLine.some(function (line) { return codeWithoutComments.startsWith(line); });
|
|
8
9
|
var isPage = pageNoExt.endsWith('/page') && normalizedResourcePath.startsWith(normalizedPagesPath);
|
|
9
10
|
if (!isPage && !isClientCode)
|
|
10
11
|
return code;
|
package/lib/esm/utils.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-translate-plugin",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Tiny and powerful i18n plugin to translate your Next.js pages.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -35,7 +35,8 @@
|
|
|
35
35
|
"loader*",
|
|
36
36
|
"template*",
|
|
37
37
|
"types*",
|
|
38
|
-
"utils*"
|
|
38
|
+
"utils*",
|
|
39
|
+
"postinstall-message.js"
|
|
39
40
|
],
|
|
40
41
|
"scripts": {
|
|
41
42
|
"build": "yarn clean && cross-env NODE_ENV=production && yarn tsc",
|
|
@@ -48,7 +49,8 @@
|
|
|
48
49
|
"test": "cross-env NODE_ENV=test jest --env=jsdom",
|
|
49
50
|
"test:coverage": "cross-env NODE_ENV=test jest --env=jsdom --coverage",
|
|
50
51
|
"test:watch": "cross-env NODE_ENV=test jest --env=jsdom --watch",
|
|
51
|
-
"tsc": "tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && node build-packages.js"
|
|
52
|
+
"tsc": "tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && node build-packages.js",
|
|
53
|
+
"postinstall": "node ./postinstall-message.js"
|
|
52
54
|
},
|
|
53
55
|
"dependencies": {
|
|
54
56
|
"typescript": "4.5.2"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
console.log('\x1b[31m%s\x1b[0m', `----------------------------------\n`);
|
|
2
|
+
|
|
3
|
+
console.log('\x1b[36m%s\x1b[0m', `Hi there!\n`);
|
|
4
|
+
|
|
5
|
+
console.log('\x1b[36m%s\x1b[0m', `Thank you for using Next-translate and Next-translate-plugin. I'm happy to see that it's been helpful to so many people ๐งก\n`);
|
|
6
|
+
|
|
7
|
+
console.log('\x1b[36m%s\x1b[0m', `As much as I enjoy maintaining and developing new features for the library, it unfortunately doesn't pay the bills. If you believe in the project and would like to support its continued growth, please consider making a donation. Any amount, no matter how small, will be greatly appreciated and will help me to continue dedicating my time to this project.\n`);
|
|
8
|
+
|
|
9
|
+
console.log('\x1b[36m%s\x1b[0m', `Also, I would be incredibly grateful if you could help me spread the word about the library and encourage any large companies you know to consider supporting the project.\n`);
|
|
10
|
+
|
|
11
|
+
console.log('\x1b[36m%s\x1b[0m', `Thank you from the bottom of my heart ๐๐ค\n`);
|
|
12
|
+
|
|
13
|
+
console.log('\x1b[31m%s\x1b[0m', `Become a sponsor: https://github.com/sponsors/aralroca\n`);
|
|
14
|
+
|
|
15
|
+
console.log('\x1b[31m%s\x1b[0m', `----------------------------------\n`);
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
package/utils.d.ts
CHANGED
|
@@ -20,3 +20,4 @@ export declare function isPageToIgnore(pageFilePath: string): boolean;
|
|
|
20
20
|
export declare function hasHOC(filePkg: ParsedFilePkg): boolean;
|
|
21
21
|
export declare function isNotExportModifier(modifier: ts.Modifier): boolean;
|
|
22
22
|
export declare function interceptExport(filePkg: ParsedFilePkg, exportName: string, defaultLocalName: string): string;
|
|
23
|
+
export declare function removeCommentsFromCode(code: string): string;
|