Skip to content

Commit 6f1bf85

Browse files
♻️ Move to ESM (BetaHuhn#288)
* fix: ignore `.git` folder when checking orphaned files * ncc * chore: move to ESM * less line change * ncc * format * add licenses, minify dist * rebuild dist Co-authored-by: BetaHuhn <[email protected]>
1 parent eb95ce4 commit 6f1bf85

File tree

8 files changed

+137
-23439
lines changed

8 files changed

+137
-23439
lines changed

dist/index.js

Lines changed: 1 addition & 23378 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/licenses.txt

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
@actions/core
2+
MIT
3+
The MIT License (MIT)
4+
5+
Copyright 2019 GitHub
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8+
9+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10+
11+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12+
13+
@actions/http-client
14+
MIT
15+
Actions Http Client for Node.js
16+
17+
Copyright (c) GitHub, Inc.
18+
19+
All rights reserved.
20+
21+
MIT License
22+
23+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
24+
associated documentation files (the "Software"), to deal in the Software without restriction,
25+
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
26+
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
27+
subject to the following conditions:
28+
29+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
30+
31+
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
32+
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
33+
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
34+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
35+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36+
37+
38+
@vercel/ncc
39+
MIT
40+
Copyright 2018 ZEIT, Inc.
41+
42+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
43+
44+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
45+
46+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
47+
48+
tunnel
49+
MIT
50+
The MIT License (MIT)
51+
52+
Copyright (c) 2012 Koichi Kobayashi
53+
54+
Permission is hereby granted, free of charge, to any person obtaining a copy
55+
of this software and associated documentation files (the "Software"), to deal
56+
in the Software without restriction, including without limitation the rights
57+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
58+
copies of the Software, and to permit persons to whom the Software is
59+
furnished to do so, subject to the following conditions:
60+
61+
The above copyright notice and this permission notice shall be included in
62+
all copies or substantial portions of the Software.
63+
64+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
65+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
66+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
67+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
68+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
69+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
70+
THE SOFTWARE.
71+
72+
73+
uuid
74+
MIT
75+
The MIT License (MIT)
76+
77+
Copyright (c) 2010-2020 Robert Kieffer and other contributors
78+
79+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
80+
81+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
82+
83+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

dist/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "module"
3+
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
"version": "1.19.1",
44
"description": "GitHub Action to keep files like Action workflows or entire directories in sync between multiple repositories.",
55
"main": "dist/index.js",
6+
"type": "module",
67
"scripts": {
78
"lint": "eslint ./src",
89
"start": "node src/index.js",
9-
"build": "ncc build src/index.js -o dist"
10+
"build": "ncc build src/index.js -o dist -m --license licenses.txt"
1011
},
1112
"repository": {
1213
"type": "git",

src/config.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const core = require('@actions/core')
2-
const yaml = require('js-yaml')
3-
const fs = require('fs-extra')
4-
const path = require('path')
5-
const { getInput } = require('action-input-parser')
1+
import * as core from '@actions/core'
2+
import * as yaml from 'js-yaml'
3+
import * as fs from 'fs-extra'
4+
import * as path from 'path'
5+
import { getInput } from 'action-input-parser'
66

77
const REPLACE_DEFAULT = true
88
const TEMPLATE_DEFAULT = false
@@ -197,7 +197,7 @@ const parseFiles = (files) => {
197197
})
198198
}
199199

200-
const parseConfig = async () => {
200+
export async function parseConfig() {
201201
const fileContent = await fs.promises.readFile(context.CONFIG_PATH)
202202

203203
const configObject = yaml.load(fileContent.toString())
@@ -247,7 +247,4 @@ const parseConfig = async () => {
247247
return Object.values(result)
248248
}
249249

250-
module.exports = {
251-
...context,
252-
parseConfig
253-
}
250+
export default context

src/git.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
const { parse } = require('@putout/git-status-porcelain')
2-
const core = require('@actions/core')
3-
const github = require('@actions/github')
4-
const { GitHub, getOctokitOptions } = require('@actions/github/lib/utils')
5-
const { throttling } = require('@octokit/plugin-throttling')
6-
const path = require('path')
7-
const fs = require('fs')
8-
9-
const {
1+
import { parse } from '@putout/git-status-porcelain'
2+
import * as core from '@actions/core'
3+
import * as github from '@actions/github'
4+
import { GitHub, getOctokitOptions } from '@actions/github/lib/utils'
5+
import { throttling } from '@octokit/plugin-throttling'
6+
import * as path from 'path'
7+
import * as fs from 'fs/promises'
8+
9+
import {
1010
GITHUB_TOKEN,
1111
IS_INSTALLATION_TOKEN,
1212
IS_FINE_GRAINED,
@@ -21,11 +21,11 @@ const {
2121
PR_BODY,
2222
BRANCH_PREFIX,
2323
FORK
24-
} = require('./config')
24+
} from './config'
2525

26-
const { dedent, execCmd } = require('./helpers')
26+
import { dedent, execCmd } from './helpers'
2727

28-
class Git {
28+
export default class Git {
2929
constructor() {
3030
const Octokit = GitHub.plugin(throttling)
3131

@@ -196,7 +196,7 @@ class Git {
196196

197197
async getBlobBase64Content(file) {
198198
const fileRelativePath = path.join(this.workingDir, file)
199-
const fileContent = await fs.promises.readFile(fileRelativePath)
199+
const fileContent = await fs.readFile(fileRelativePath)
200200

201201
return fileContent.toString('base64')
202202
}
@@ -521,6 +521,4 @@ class Git {
521521
})
522522
this.lastCommitSha = request.data.sha
523523
}
524-
}
525-
526-
module.exports = Git
524+
}

src/helpers.js

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
const fs = require('fs-extra')
2-
const readfiles = require('node-readfiles')
3-
const { exec } = require('child_process')
4-
const core = require('@actions/core')
5-
const path = require('path')
6-
const nunjucks = require('nunjucks')
1+
import * as fs from 'fs-extra'
2+
import readfiles from 'node-readfiles'
3+
import { exec } from 'child_process'
4+
import * as core from '@actions/core'
5+
import * as path from 'path'
6+
import * as nunjucks from 'nunjucks'
77

88
nunjucks.configure({ autoescape: true, trimBlocks: true, lstripBlocks: true })
99

1010
// From https://github.com/toniov/p-iteration/blob/master/lib/static-methods.js - MIT © Antonio V
11-
const forEach = async (array, callback) => {
11+
export async function forEach(array, callback) {
1212
for (let index = 0; index < array.length; index++) {
1313
// eslint-disable-next-line callback-return
1414
await callback(array[index], index, array)
1515
}
1616
}
1717

1818
// From https://github.com/MartinKolarik/dedent-js/blob/master/src/index.ts - MIT © 2015 Martin Kolárik
19-
const dedent = function(templateStrings, ...values) {
19+
export function dedent(templateStrings, ...values) {
2020
const matches = []
2121
const strings = typeof templateStrings === 'string' ? [ templateStrings ] : templateStrings.slice()
2222
strings[strings.length - 1] = strings[strings.length - 1].replace(/\r?\n([\t ]*)$/, '')
@@ -42,7 +42,7 @@ const dedent = function(templateStrings, ...values) {
4242
return string
4343
}
4444

45-
const execCmd = (command, workingDir, trimResult = true) => {
45+
export function execCmd(command, workingDir, trimResult = true) {
4646
core.debug(`EXEC: "${ command }" IN ${ workingDir }`)
4747
return new Promise((resolve, reject) => {
4848
exec(
@@ -60,22 +60,24 @@ const execCmd = (command, workingDir, trimResult = true) => {
6060
})
6161
}
6262

63-
const addTrailingSlash = (str) => str.endsWith('/') ? str : str + '/'
63+
export function addTrailingSlash(str) {
64+
return str.endsWith('/') ? str : str + '/'
65+
}
6466

65-
const pathIsDirectory = async (path) => {
67+
export async function pathIsDirectory(path) {
6668
const stat = await fs.lstat(path)
6769
return stat.isDirectory()
6870
}
6971

70-
const write = async (src, dest, context) => {
72+
export async function write(src, dest, context) {
7173
if (typeof context !== 'object') {
7274
context = {}
7375
}
7476
const content = nunjucks.render(src, context)
7577
await fs.outputFile(dest, content)
7678
}
7779

78-
const copy = async (src, dest, isDirectory, file) => {
80+
export async function copy(src, dest, isDirectory, file) {
7981
const deleteOrphaned = isDirectory && file.deleteOrphaned
8082

8183
const filterFunc = (file) => {
@@ -154,22 +156,13 @@ const copy = async (src, dest, isDirectory, file) => {
154156
}
155157
}
156158

157-
const remove = async (src) => {
159+
export async function remove(src) {
158160

159161
core.debug(`RM: ${ src }`)
160162

161163
return fs.remove(src)
162164
}
163165

164-
const arrayEquals = (array1, array2) => Array.isArray(array1) && Array.isArray(array2) && array1.length === array2.length && array1.every((value, i) => value === array2[i])
165-
166-
module.exports = {
167-
forEach,
168-
dedent,
169-
addTrailingSlash,
170-
pathIsDirectory,
171-
execCmd,
172-
copy,
173-
remove,
174-
arrayEquals
175-
}
166+
export function arrayEquals(array1, array2) {
167+
return Array.isArray(array1) && Array.isArray(array2) && array1.length === array2.length && array1.every((value, i) => value === array2[i])
168+
}

src/index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
const core = require('@actions/core')
2-
const fs = require('fs')
1+
import * as core from '@actions/core'
2+
import * as fs from 'fs'
33

4-
const Git = require('./git')
5-
const { forEach, dedent, addTrailingSlash, pathIsDirectory, copy, remove, arrayEquals } = require('./helpers')
4+
import Git from './git'
5+
import { forEach, dedent, addTrailingSlash, pathIsDirectory, copy, remove, arrayEquals } from './helpers'
6+
7+
import { parseConfig, default as config } from './config'
68

79
const {
8-
parseConfig,
910
COMMIT_EACH_FILE,
1011
COMMIT_PREFIX,
1112
PR_LABELS,
@@ -20,9 +21,9 @@ const {
2021
FORK,
2122
REVIEWERS,
2223
TEAM_REVIEWERS
23-
} = require('./config')
24+
} = config
2425

25-
const run = async () => {
26+
async function run() {
2627
// Reuse octokit for each repo
2728
const git = new Git()
2829

@@ -216,7 +217,6 @@ const run = async () => {
216217
}
217218

218219
run()
219-
.then(() => {})
220220
.catch((err) => {
221221
core.setFailed(err.message)
222222
core.debug(err)

0 commit comments

Comments
 (0)