Skip to content

Commit 6ba3d45

Browse files
authored
Merge pull request #334 from finale-lua/bundle-remove-comments
Remove comments when bundling
2 parents 8930e60 + 1ae0560 commit 6ba3d45

File tree

4 files changed

+89
-3
lines changed

4 files changed

+89
-3
lines changed

.github/actions/bundle/dist/index.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -4501,6 +4501,7 @@ const fs_1 = __importDefault(__nccwpck_require__(7147));
45014501
const path_1 = __importDefault(__nccwpck_require__(1017));
45024502
const helpers_1 = __nccwpck_require__(8092);
45034503
const lua_require_1 = __nccwpck_require__(9083);
4504+
const remove_comments_1 = __nccwpck_require__(6236);
45044505
const wrap_import_1 = __nccwpck_require__(3494);
45054506
exports.files = {};
45064507
const importFileBase = (name, importedFiles, fetcher) => {
@@ -4551,7 +4552,7 @@ const bundleFileBase = (name, importedFiles, mixins, fetcher) => {
45514552
};
45524553
exports.bundleFileBase = bundleFileBase;
45534554
const bundleFile = (name, sourcePath, mixins) => {
4554-
return (0, exports.bundleFileBase)(name, exports.files, mixins, (fileName) => fs_1.default.readFileSync(path_1.default.join(sourcePath, fileName)).toString());
4555+
return (0, remove_comments_1.removeComments)((0, exports.bundleFileBase)(name, exports.files, mixins, (fileName) => fs_1.default.readFileSync(path_1.default.join(sourcePath, fileName)).toString()));
45554556
};
45564557
exports.bundleFile = bundleFile;
45574558

@@ -4676,6 +4677,25 @@ const resolveRequiredFile = (name) => {
46764677
exports.resolveRequiredFile = resolveRequiredFile;
46774678

46784679

4680+
/***/ }),
4681+
4682+
/***/ 6236:
4683+
/***/ ((__unused_webpack_module, exports) => {
4684+
4685+
"use strict";
4686+
4687+
Object.defineProperty(exports, "__esModule", ({ value: true }));
4688+
exports.removeComments = void 0;
4689+
const removeComments = (contents) => {
4690+
return contents
4691+
.replace(/--\[\[[^\]]*\]\]/giu, '')
4692+
.replace(/--.*$/gimu, '')
4693+
.replace(/\n\n+/gimu, '\n')
4694+
.replace(/ *$/gimu, '');
4695+
};
4696+
exports.removeComments = removeComments;
4697+
4698+
46794699
/***/ }),
46804700

46814701
/***/ 3494:

.github/actions/bundle/src/bundle.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import fs from 'fs'
22
import path from 'path'
33
import { getAllImports } from './helpers'
44
import { generateLuaRequire, resolveRequiredFile } from './lua-require'
5+
import { removeComments } from './remove-comments'
56
import { wrapImport } from './wrap-import'
67

78
export type ImportedFile = {
@@ -62,7 +63,9 @@ export const bundleFileBase = (
6263
}
6364

6465
export const bundleFile = (name: string, sourcePath: string, mixins: string[]): string => {
65-
return bundleFileBase(name, files, mixins, (fileName: string) =>
66-
fs.readFileSync(path.join(sourcePath, fileName)).toString()
66+
return removeComments(
67+
bundleFileBase(name, files, mixins, (fileName: string) =>
68+
fs.readFileSync(path.join(sourcePath, fileName)).toString()
69+
)
6770
)
6871
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { removeComments } from './remove-comments'
2+
3+
const tests: [string, string][] = [
4+
[`--[[]]`, ``],
5+
[`--[[hello world]]`, ``],
6+
[`--[[[[]]]]`, `]]`],
7+
[`--[[--[[]]]]`, `]]`],
8+
[`--[[]]--`, ``],
9+
[`--[[]]--\nhello world`, `\nhello world`],
10+
[`\n\n`, `\n`],
11+
[`\n\n\n`, `\n`],
12+
[`\n\n\n\n`, `\n`],
13+
[`\n\n\n\n\n`, `\n`],
14+
[`--[[\nhello\nworld\n]]`, ``],
15+
[`--[[\n--hello\nworld\n]]`, ``],
16+
[`hello world --[[\n--hello\nworld\n]]`, `hello world`],
17+
[`hello world -- this is a comment`, `hello world`],
18+
[` -- this is a comment\nhello world`, `\nhello world`],
19+
[
20+
`finaleplugin.AdditionalMenuOptions = [[ CrossStaff Offset No Dialog ]] `,
21+
`finaleplugin.AdditionalMenuOptions = [[ CrossStaff Offset No Dialog ]]`,
22+
],
23+
[
24+
`finaleplugin.AdditionalMenuOptions = [[\n CrossStaff Offset No Dialog\n]]`,
25+
`finaleplugin.AdditionalMenuOptions = [[\n CrossStaff Offset No Dialog\n]]`,
26+
],
27+
[
28+
`
29+
__imports["library.client"] = function()
30+
--[[
31+
$module Client
32+
Get information about the current client. For the purposes of Finale Lua, the client is
33+
the Finale application that's running on someones machine. Therefore, the client has
34+
details about the user's setup, such as their Finale version, plugin version, and
35+
operating system.
36+
One of the main uses of using client details is to check its capabilities. As such,
37+
the bulk of this library is helper functions to determine what the client supports.
38+
]] --
39+
local client = {}
40+
41+
local function to_human_string(feature)
42+
return string.gsub(feature, "_", " ")
43+
end`,
44+
`
45+
__imports["library.client"] = function()
46+
47+
local client = {}
48+
local function to_human_string(feature)
49+
return string.gsub(feature, "_", " ")
50+
end`,
51+
],
52+
]
53+
54+
it.each(tests)(`removeComments(%p)`, (input, expected) => {
55+
expect(removeComments(input)).toBe(expected)
56+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const removeComments = (contents: string): string => {
2+
return contents
3+
.replace(/--\[\[[^\]]*\]\]/giu, '')
4+
.replace(/--.*$/gimu, '')
5+
.replace(/\n\n+/gimu, '\n')
6+
.replace(/ *$/gimu, '')
7+
}

0 commit comments

Comments
 (0)